1# Slider
2
3The **Slider** component is used to quickly adjust settings, such as the volume and brightness.
4
5>  **NOTE**
6>
7>  This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8
9
10## Child Components
11
12Not supported
13
14
15## APIs
16
17Slider(options?: SliderOptions)
18
19**Widget capability**: This API can be used in ArkTS widgets since API version 9.
20
21**Atomic service API**: This API can be used in atomic services since API version 11.
22
23**System capability**: SystemCapability.ArkUI.ArkUI.Full
24
25**Parameters**
26
27| Name | Type                                   | Mandatory| Description              |
28| ------- | --------------------------------------- | ---- | ------------------ |
29| options | [SliderOptions](#slideroptions) | No  | Parameters of the slider.|
30
31## SliderOptions
32
33**Widget capability**: This API can be used in ArkTS widgets since API version 9.
34
35**Atomic service API**: This API can be used in atomic services since API version 11.
36
37**System capability**: SystemCapability.ArkUI.ArkUI.Full
38
39| Name| Type| Mandatory| Description|
40| -------- | -------- | -------- | -------- |
41| value | number | No| Current progress.<br>Default value: same as the value of **min**<br>Since API version 10, this parameter supports two-way binding through [$$](../../../quick-start/arkts-two-way-sync.md).|
42| min | number | No| Minimum value.<br>Default value: **0**|
43| max | number | No| Maximum value.<br>Default value: **100**<br>**NOTE**<br>If the value of **min** is greater than or equal to the value of **max**, the **min** value defaults to **0**, and the **max** value defaults to **100**.<br>If the value is not within the [min, max] range, the value of **min** or **max** is used, whichever is closer.|
44| step | number | No| Step of the slider.<br>Default value: **1**<br>Value range: [0.01, max - min]<br>**NOTE**<br>If this parameter is set to a value less than 0 or greater than the value of **max**, the default value is used.|
45| style | [SliderStyle](#sliderstyle) | No| Style of the slider thumb and track.<br>Default value: **SliderStyle.OutSet**|
46| direction<sup>8+</sup> | [Axis](ts-appendix-enums.md#axis) | No| Whether the slider moves horizontally or vertically.<br>Default value: **Axis.Horizontal**|
47| reverse<sup>8+</sup> | boolean | No| Whether the slider values are reversed. By default, the values increase from left to right for a horizontal slider and from top to bottom for a vertical slider.<br>Default value: **false**|
48
49## SliderStyle
50
51**System capability**: SystemCapability.ArkUI.ArkUI.Full
52
53| Name| Description|
54| -------- | -------- |
55| OutSet | The thumb is on the track.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
56| InSet | The thumb is in the track.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
57| NONE<sup>12+</sup> | There is no thumb.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
58
59## Attributes
60
61All the [universal attributes](ts-universal-attributes-size.md) except **responseRegion** are supported
62
63### blockColor
64
65blockColor(value: ResourceColor)
66
67Sets the color of the thumb.
68
69When **SliderBlockType.DEFAULT** is used, **blockColor** sets the color of the round thumb.
70
71When **SliderBlockType.IMAGE** is used, **blockColor** does not work as the thumb has no fill color.
72
73When **SliderBlockType.SHAPE** is used, **blockColor** sets the color of the thumb in a custom shape.
74
75**Widget capability**: This API can be used in ArkTS widgets since API version 9.
76
77**Atomic service API**: This API can be used in atomic services since API version 11.
78
79**System capability**: SystemCapability.ArkUI.ArkUI.Full
80
81**Parameters**
82
83| Name| Type                                      | Mandatory| Description                               |
84| ------ | ------------------------------------------ | ---- | ----------------------------------- |
85| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Color of the thumb.<br>Default value: **$r('sys.color.ohos_id_color_foreground_contrary')**|
86
87### trackColor
88
89trackColor(value: ResourceColor | LinearGradient)
90
91Sets the background color of the track.
92
93**LinearGradient** is supported since API version 12.
94
95**Widget capability**: This API can be used in ArkTS widgets since API version 9.
96
97**Atomic service API**: This API can be used in atomic services since API version 11.
98
99**System capability**: SystemCapability.ArkUI.ArkUI.Full
100
101**Parameters**
102
103| Name| Type                                                        | Mandatory| Description                                                        |
104| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
105| value  | [ResourceColor](ts-types.md#resourcecolor) \| [LinearGradient<sup>12+</sup>](ts-basic-components-datapanel.md#lineargradient10) | Yes  | Background color of the track.<br>**NOTE**<br>With gradient color settings, if the color stop values are invalid or if the color stops are empty, the gradient effect will not be applied.<br>Default value: **$r('sys.color.ohos_id_color_component_normal')**<br>The LinearGradient type cannot be used in atomic services.|
106
107### selectedColor
108
109selectedColor(value: ResourceColor)
110
111Sets the color of the portion of the track between the minimum value and the thumb.
112
113**Widget capability**: This API can be used in ArkTS widgets since API version 9.
114
115**Atomic service API**: This API can be used in atomic services since API version 11.
116
117**System capability**: SystemCapability.ArkUI.ArkUI.Full
118
119**Parameters**
120
121| Name| Type                                      | Mandatory| Description                                         |
122| ------ | ------------------------------------------ | ---- | --------------------------------------------- |
123| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Color of the portion of the track between the minimum value and the thumb.<br>Default value: **$r('sys.color.ohos_id_color_emphasize')**|
124
125### showSteps
126
127showSteps(value: boolean)
128
129Sets whether to display the current step.
130
131**Widget capability**: This API can be used in ArkTS widgets since API version 9.
132
133**Atomic service API**: This API can be used in atomic services since API version 11.
134
135**System capability**: SystemCapability.ArkUI.ArkUI.Full
136
137**Parameters**
138
139| Name| Type   | Mandatory| Description                                      |
140| ------ | ------- | ---- | ------------------------------------------ |
141| value  | boolean | Yes  | Whether to display the current step.<br>Default value: **false**|
142
143### showTips
144
145showTips(value: boolean, content?: ResourceStr)
146
147Sets whether to display a tooltip when the user drags the slider.
148
149When **direction** is set to **Axis.Horizontal**, the tooltip is displayed right above the slider; if there is insufficient space above, it will be displayed below. When **direction** is set to **Axis.Vertical**, the tooltip is displayed on the left of the slider; if there is insufficient space on the left, it will be displayed on the right. If the margins are not set or are set to small values, the tooltip may be clipped.
150
151The drawing area of the tooltip is the overlay of the slider.
152
153**Widget capability**: This API can be used in ArkTS widgets since API version 9.
154
155**Atomic service API**: This API can be used in atomic services since API version 11.
156
157**System capability**: SystemCapability.ArkUI.ArkUI.Full
158
159**Parameters**
160
161| Name               | Type                                  | Mandatory| Description                                      |
162| --------------------- | -------------------------------------- | ---- | ------------------------------------------ |
163| value                 | boolean                                | Yes  | Whether to display a tooltip when the user drags the slider.<br>Default value: **false**|
164| content<sup>10+</sup> | [ResourceStr](ts-types.md#resourcestr) | No  | Content of the tooltip. By default, the tooltip shows the current percentage value.  |
165
166### trackThickness<sup>8+</sup>
167
168trackThickness(value: Length)
169
170Sets the thickness of the track. If the value is less than or equal to 0, the default value is used.
171
172To ensure [SliderStyle](#sliderstyle) works as expected for the thumb and track, [blockSize](#blocksize10) should increase or decrease proportionally with **trackThickness**.
173
174Specially, when **style** is **[SliderStyle](#sliderstyle).OutSet**, trackThickness: [blockSize](#blocksize10) = 1:4; when **style** is **[SliderStyle](#sliderstyle).InSet**, trackThickness: [blockSize](#blocksize10) = 5:3.
175
176In changing the value of **trackThickness**, if it or the value of [blockSize](#blocksize10) exceeds the width or height of the slider, the default value is used. (When **style** is **[SliderStyle](#sliderstyle).OutSet**, it is possible that only the value of [blockSize](#blocksize10) exceeds the height of the slider.)
177
178**Widget capability**: This API can be used in ArkTS widgets since API version 9.
179
180**Atomic service API**: This API can be used in atomic services since API version 11.
181
182**System capability**: SystemCapability.ArkUI.ArkUI.Full
183
184**Parameters**
185
186| Name| Type                        | Mandatory| Description                                                        |
187| ------ | ---------------------------- | ---- | ------------------------------------------------------------ |
188| value  | [Length](ts-types.md#length) | Yes  | Thickness of the track.<br>Default value: 4.0vp when **style** is set to **[SliderStyle](#sliderstyle).OutSet**; 20.0vp when **style** is set to **[SliderStyle](#sliderstyle).InSet**|
189
190### blockBorderColor<sup>10+</sup>
191
192blockBorderColor(value: ResourceColor)
193
194Sets the border color of the slider in the block direction.
195
196When **SliderBlockType.DEFAULT** is used, **blockBorderColor** sets the border color of the round slider.
197
198When **SliderBlockType.IMAGE** is used, **blockBorderColor** does not work as the slider has no border.
199
200When **SliderBlockType.SHAPE** is used, **blockBorderColor** sets the border color of the slider in a custom shape.
201
202**Atomic service API**: This API can be used in atomic services since API version 11.
203
204**System capability**: SystemCapability.ArkUI.ArkUI.Full
205
206**Parameters**
207
208| Name| Type                                      | Mandatory| Description                                  |
209| ------ | ------------------------------------------ | ---- | -------------------------------------- |
210| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Border color of the slider in the block direction.<br>Default value: **'#00000000'**|
211
212### blockBorderWidth<sup>10+</sup>
213
214blockBorderWidth(value: Length)
215
216Sets the border width of the slider in the block direction.
217
218When **SliderBlockType.DEFAULT** is used, **blockBorderWidth** sets the border width of the round slider.
219
220When **SliderBlockType.IMAGE** is used, **blockBorderWidth** does not work as the slider has no border.
221
222WWhen **SliderBlockType.SHAPE** is used, **blockBorderWidth** sets the border width of the slider in a custom shape.
223
224**Atomic service API**: This API can be used in atomic services since API version 11.
225
226**System capability**: SystemCapability.ArkUI.ArkUI.Full
227
228**Parameters**
229
230| Name| Type                        | Mandatory| Description          |
231| ------ | ---------------------------- | ---- | -------------- |
232| value  | [Length](ts-types.md#length) | Yes  | Border width of the slider in the block direction.|
233
234### stepColor<sup>10+</sup>
235
236stepColor(value: ResourceColor)
237
238Sets the step color.
239
240**Atomic service API**: This API can be used in atomic services since API version 11.
241
242**System capability**: SystemCapability.ArkUI.ArkUI.Full
243
244**Parameters**
245
246| Name| Type                                      | Mandatory| Description                              |
247| ------ | ------------------------------------------ | ---- | ---------------------------------- |
248| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Step color.<br>Default value:<br>**$r('sys.color.ohos_id_color_foreground')** mixed with<br>**$r('sys.color.ohos_id_alpha_normal_bg')** transparency|
249
250### trackBorderRadius<sup>10+</sup>
251
252trackBorderRadius(value: Length)
253
254Sets the radius of the rounded corner of the track.
255
256**Atomic service API**: This API can be used in atomic services since API version 11.
257
258**System capability**: SystemCapability.ArkUI.ArkUI.Full
259
260**Parameters**
261
262| Name| Type                        | Mandatory| Description                            |
263| ------ | ---------------------------- | ---- | -------------------------------- |
264| value  | [Length](ts-types.md#length) | Yes  | Radius of the rounded corner of the track.<br>Default value:<br>**'2vp'** when **style** is **SliderStyle.OutSet**<br>**'10vp'** when **style** is **SliderStyle.InSet**|
265
266### selectedBorderRadius<sup>12+</sup>
267
268selectedBorderRadius(value: Dimension)
269
270Set the corner radius of the selected (highlighted) part of the slider.
271
272**Atomic service API**: This API can be used in atomic services since API version 12.
273
274**System capability**: SystemCapability.ArkUI.ArkUI.Full
275
276**Parameters**
277
278| Name| Type                        | Mandatory| Description                            |
279| ------ | ---------------------------- | ---- | -------------------------------- |
280| value  | [Dimension](ts-types.md#dimension10)| Yes  | Corner radius of the selected part of the slider.<br>Default value:<br>- For **SliderStyle.InSet** or **SliderStyle.OutSet**: same as the corner radius of the background<br>- **SliderStyle.NONE**: **0**|
281
282### blockSize<sup>10+</sup>
283
284blockSize(value: SizeOptions)
285
286Sets the size of the slider in the block direction.
287
288When the slider type is set to **SliderBlockType.DEFAULT**, the smaller of the width and height values is used as the radius of the circle.
289
290When the slider type is set to **SliderBlockType.IMAGE**, this API sets the size of the image, which is scaled using the **ObjectFit.Cover** strategy.
291
292When the slider type is set to **SliderBlockType.SHAPE**, this API sets the size of the custom shape, which is also scaled using the **ObjectFit.Cover** strategy.
293
294**Atomic service API**: This API can be used in atomic services since API version 11.
295
296**System capability**: SystemCapability.ArkUI.ArkUI.Full
297
298**Parameters**
299
300| Name| Type                                  | Mandatory| Description                                                        |
301| ------ | -------------------------------------- | ---- | ------------------------------------------------------------ |
302| value  | [SizeOptions](ts-types.md#sizeoptions) | Yes  | Size of the slider in the block direction.<br>Default value:<br>For [SliderStyle](#sliderstyle).OutSet: **{width: 16, height: 16}**<br/>- For [SliderStyle](#sliderstyle).InSet: **{width: 12, height: 12}**<br/>- For [SliderStyle](#sliderstyle).NONE: This parameter is not effective.<br>If the set **blockSize** has different width and height values, the smaller value is taken. If one or both of the width and height values are less than or equal to 0, the default value is used instead.|
303
304### blockStyle<sup>10+</sup>
305
306blockStyle(value: SliderBlockStyle)
307
308Sets the style of the slider in the block direction.
309
310**Atomic service API**: This API can be used in atomic services since API version 11.
311
312**System capability**: SystemCapability.ArkUI.ArkUI.Full
313
314**Parameters**
315
316| Name| Type                                           | Mandatory| Description                                                        |
317| ------ | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
318| value  | [SliderBlockStyle](#sliderblockstyle10) | Yes  | Style of the slider in the block direction.<br>Default value: **SliderBlockType.DEFAULT**, indicating the round slider.|
319
320### stepSize<sup>10+</sup>
321
322stepSize(value: Length)
323
324Sets the step size (diameter). If the value is 0, the step size is not displayed. If the value is less than 0, the default value is used.
325
326**Atomic service API**: This API can be used in atomic services since API version 11.
327
328**System capability**: SystemCapability.ArkUI.ArkUI.Full
329
330**Parameters**
331
332| Name| Type                        | Mandatory| Description                                 |
333| ------ | ---------------------------- | ---- | ------------------------------------- |
334| value  | [Length](ts-types.md#length) | Yes  | Step size (diameter).<br>Default value: **'4vp'**<br>Value range: [0, trackThickness)|
335
336### minLabel<sup>(deprecated)</sup>
337
338minLabel(value: string)
339
340Sets the minimum value.
341
342This API is deprecated since API version 9. You are advised to use **min** instead.
343
344**System capability**: SystemCapability.ArkUI.ArkUI.Full
345
346**Parameters**
347
348| Name| Type  | Mandatory| Description    |
349| ------ | ------ | ---- | -------- |
350| value  | string | Yes  | Minimum value.|
351
352### maxLabel<sup>(deprecated)</sup>
353
354maxLabel(value: string)
355
356Sets the maximum value.
357
358This API is deprecated since API version 9. You are advised to use **max** instead.
359
360**System capability**: SystemCapability.ArkUI.ArkUI.Full
361
362**Parameters**
363
364| Name| Type  | Mandatory| Description    |
365| ------ | ------ | ---- | -------- |
366| value  | string | Yes  | Maximum value.|
367
368>  **NOTE**
369>
370>  - By default, the slider has no padding.
371>  - A horizontal slider is displayed in the center with the following default settings: 40 vp height, width equal with that of the parent container, 10 vp left and right margins not covered by any padding (if set).
372>  - A vertical slider is displayed in the center with the following default settings: 40 vp width, height equal with that of the parent container, 6 vp top and bottom margins not covered by any padding (if set).
373
374### sliderInteractionMode<sup>12+</sup>
375
376sliderInteractionMode(value: SliderInteraction)
377
378Sets the interaction mode between the user and the slider.
379
380**Atomic service API**: This API can be used in atomic services since API version 12.
381
382**System capability**: SystemCapability.ArkUI.ArkUI.Full
383
384**Parameters**
385
386| Name| Type                                             | Mandatory| Description                                                        |
387| ------ | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
388| value  | [SliderInteraction](#sliderinteraction12)| Yes  | Interaction mode between the user and the slider.<br> Default value: **SliderInteraction.SLIDE_AND_CLICK**|
389
390### minResponsiveDistance<sup>12+</sup>
391
392minResponsiveDistance(value: number)
393
394Sets the minimum distance required for the slider to respond.
395
396**Atomic service API**: This API can be used in atomic services since API version 12.
397
398**System capability**: SystemCapability.ArkUI.ArkUI.Full
399
400**Parameters**
401
402| Name| Type   | Mandatory| Description                                      |
403| ------ | ------- | ---- | ------------------------------------------ |
404| value  | number | Yes  | Minimum distance required for the slider to respond. The slider will only respond and move when the sliding distance exceeds this threshold.<br>**NOTE**<br>The unit is the same as that of **min** and **max**.<br>If the value is less than 0, greater than the result of (max - min), or invalid, the default value is used.<br>Default value: **0**|
405
406### contentModifier<sup>12+</sup>
407
408contentModifier(modifier: ContentModifier\<SliderConfiguration>)
409
410Creates a content modifier.
411
412**Atomic service API**: This API can be used in atomic services since API version 12.
413
414**System capability**: SystemCapability.ArkUI.ArkUI.Full
415
416**Parameters**
417
418| Name| Type                                         | Mandatory| Description                                            |
419| ------ | --------------------------------------------- | ---- | ------------------------------------------------ |
420| modifier  | [ContentModifier\<SliderConfiguration>](#sliderconfiguration12)| Yes  | Content modifier to apply to the slider.<br>**modifier**: content modifier. You need a custom class to implement the **ContentModifier** API.|
421
422>  **NOTE**
423>
424>  - If **contentModifier** is set, then clicks and swipes within the custom area will not trigger the **onChange** event of the original slider.
425>  - The **onChange** event of the original slider can only be triggered when the **triggerChange** function is called with the correct parameter value.
426
427### slideRange<sup>12+</sup>
428
429slideRange(value: SlideRange)
430
431Sets the slide range.
432
433**Atomic service API**: This API can be used in atomic services since API version 12.
434
435**System capability**: SystemCapability.ArkUI.ArkUI.Full
436
437**Parameters**
438
439| Name| Type                               | Mandatory| Description            |
440| ------ | ----------------------------------- | ---- | ---------------- |
441| value  | [SlideRange](#sliderange12) | Yes  | Slide range.|
442
443## SliderBlockStyle<sup>10+</sup>
444
445Describes the style of the slider in the block direction.
446
447**Atomic service API**: This API can be used in atomic services since API version 11.
448
449**System capability**: SystemCapability.ArkUI.ArkUI.Full
450
451| Name | Type                                                        | Mandatory| Description                                                        |
452| ----- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
453| type  | [SliderBlockType](#sliderblocktype10)                | Yes  | Type of the slider in the block direction.<br>Default value: **SliderBlockType.DEFAULT**, indicating the round slider.|
454| image | [ResourceStr](ts-types.md#resourcestr)                       | No  | Image resource of the slider.<br>The area size for displaying the image is subject to the **blockSize** attribute. Be mindful of the image size when selecting an image.|
455| shape | [Circle](ts-drawing-components-circle.md) \| [Ellipse](ts-drawing-components-ellipse.md) \| [Path](ts-drawing-components-path.md) \| [Rect](ts-drawing-components-rect.md)  | No  | Custom shape of the slider.                                  |
456
457## SliderBlockType<sup>10+</sup>
458
459Enumerates the types of the slider in the block direction.
460
461**Atomic service API**: This API can be used in atomic services since API version 11.
462
463**System capability**: SystemCapability.ArkUI.ArkUI.Full
464
465| Name   | Description                |
466| ------- | ---------------------- |
467| DEFAULT | Round slider.  |
468| IMAGE   | Slider with an image background.  |
469| SHAPE   | Slider in a custom shape.|
470
471## SliderInteraction<sup>12+</sup>
472
473Enumerates the interaction modes between the user and the slider.
474
475**Atomic service API**: This API can be used in atomic services since API version 12.
476
477**System capability**: SystemCapability.ArkUI.ArkUI.Full
478
479| Name    | Description                         |
480| ------ | ----------------------------- |
481| SLIDE_AND_CLICK | Users can drag the slider or touch the track to move the slider. The slider moves as soon as the mouse or finger is pressed.|
482| SLIDE_ONLY | Users are not allowed to move the slider by touching the slider.|
483| SLIDE_AND_CLICK_UP | Users can drag the slider or touch the track to move the slider. The slider moves when the mouse is released or finger is lifted, if the release/lift position coincides with the screen press position.|
484
485## SlideRange<sup>12+</sup>
486
487Defines the callback type used in **SlideRange**.
488
489**Atomic service API**: This API can be used in atomic services since API version 12.
490
491**System capability**: SystemCapability.ArkUI.ArkUI.Full
492
493| Name| Type    | Mandatory| Description          |
494|----|--------| ---- |--------------|
495| from | number | No| Start of the slide range.|
496| to | number | No| End of the slide range.|
497
498>  **NOTE**
499>
500>  - Currently, this API takes effect only when **MIN** ≤ **from** ≤ **to** ≤ **MAX** (the values of **MIN** and **MAX** do not depend on the values set, but on the actual values that take effect).
501>  - You can set only **from** or **to**, or you can set both**from** and **to** at the same time.
502>  - When the API is effective, if the set **from** value is between the adjacent multiples of **step**, then **from** takes the value of the left interval multiple of **step** or **MIN** as the corrected value.
503>  - When the API is effective, if the set **to** value is between the adjacent multiples of **step**, then **to** takes the value of the right interval multiple of **step** or **MAX** as the corrected value.
504>  - After **from** and **to** have taken their corrected values, when **value** is **undefined** or **null**, it takes the same value as **from**; when **value** is a number type, and if **value** ≤ **from**, then it takes **from**; if **value** > **to**, then it takes **to**.
505
506## Events
507
508In addition to the [universal events](ts-universal-events-click.md), the following attributes are supported.
509
510### onChange
511
512onChange(callback: (value: number, mode: SliderChangeMode) =&gt; void)
513
514Triggered when the slider is dragged or clicked.
515
516The **Begin** and **End** states are triggered when the slider is clicked with a gesture. The **Moving** and **Click** states are triggered when the value of **value** changes.
517
518If the coherent action is a drag action, the **Click** state will not be triggered.
519
520**Widget capability**: This API can be used in ArkTS widgets since API version 9.
521
522**Atomic service API**: This API can be used in atomic services since API version 11.
523
524**System capability**: SystemCapability.ArkUI.ArkUI.Full
525
526**Parameters**
527
528| Name| Type                                         | Mandatory| Description                                                        |
529| ------ | --------------------------------------------- | ---- | ------------------------------------------------------------ |
530| value  | number                                        | Yes  | Current sliding progress. Its range of changes corresponds to the array of step sizes. If the return value contains decimals, you can use the **number.toFixed()** API to process the data to the expected precision.|
531| mode   | [SliderChangeMode](#sliderchangemode)| Yes  | State triggered by the event.                                      |
532
533## SliderChangeMode
534
535**Widget capability**: This API can be used in ArkTS widgets since API version 9.
536
537**Atomic service API**: This API can be used in atomic services since API version 11.
538
539**System capability**: SystemCapability.ArkUI.ArkUI.Full
540
541| Name| Value| Description|
542| -------- | -------- | -------- |
543| Begin | 0 | The user touches or clicks the thumb.|
544| Moving | 1 | The user is dragging the slider.|
545| End | 2 | The user stops dragging the slider by lifting their finger or releasing the mouse device.<br>**NOTE**<br>The trigger occurs when an invalid value is restored to the default value, that is, when the value is set to less than **min** or greater than **max**.|
546| Click<sup>8+</sup> | 3    | The user moves the thumb by touching or clicking the track.|
547
548## SliderConfiguration<sup>12+</sup>
549
550You need a custom class to implement the **ContentModifier** API.
551
552**Atomic service API**: This API can be used in atomic services since API version 12.
553
554**System capability**: SystemCapability.ArkUI.ArkUI.Full
555
556| Name | Type   | Read Only | Optional | Description             |
557| ------ | ------ | ---------------- | ---------------- | ---------------- |
558| value | number | No| No| Current progress.|
559| min | number | No| No| Minimum value.|
560| max | number | No| No| Maximum value.|
561| step | number | No| No| Step of the slider.|
562| triggerChange | [SliderTriggerChangeCallback](#slidertriggerchangecallback12) | No| No| Triggers slider changes.|
563
564## SliderTriggerChangeCallback<sup>12+</sup>
565
566type SliderTriggerChangeCallback = (value: number, mode: SliderChangeMode) => void
567
568Defines the callback type used in **SliderConfiguration**.
569
570**Atomic service API**: This API can be used in atomic services since API version 12.
571
572**System capability**: SystemCapability.ArkUI.ArkUI.Full
573
574**Parameters**
575
576| Name| Type   | Read Only| Optional| Description             |
577| ------ | ------ | ---- | ---------------- | ---------------- |
578| value | number | No| No| Current progress.|
579| mode | [SliderChangeMode](#sliderchangemode)| No| No| State triggered by the event.|
580
581## Example
582
583### Example 1: Using Basic Slider Styles
584
585This example demonstrates how to control the display of the tooltip, current step, and slider thumb and track by configuring **style**, **showTips**, and **showSteps**.
586
587```ts
588// xxx.ets
589@Entry
590@Component
591struct SliderExample {
592  @State outSetValueOne: number = 40
593  @State inSetValueOne: number = 40
594  @State noneValueOne: number = 40
595  @State outSetValueTwo: number = 40
596  @State inSetValueTwo: number = 40
597  @State vOutSetValueOne: number = 40
598  @State vInSetValueOne: number = 40
599  @State vOutSetValueTwo: number = 40
600  @State vInSetValueTwo: number = 40
601
602  build() {
603    Column({ space: 8 }) {
604      Text('outset slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)
605      Row() {
606        Slider({
607          value: this.outSetValueOne,
608          min: 0,
609          max: 100,
610          style: SliderStyle.OutSet
611        })
612          .showTips(true)
613          .onChange((value: number, mode: SliderChangeMode) => {
614            this.outSetValueOne = value
615            console.info('value:' + value + 'mode:' + mode.toString())
616          })
617        // toFixed(0) converts the return value of the slider to an integer.
618        Text(this.outSetValueOne.toFixed(0)).fontSize(12)
619      }
620      .width('80%')
621      Row() {
622        Slider({
623          value: this.outSetValueTwo,
624          step: 10,
625          style: SliderStyle.OutSet
626        })
627          .showSteps(true)
628          .onChange((value: number, mode: SliderChangeMode) => {
629            this.outSetValueTwo = value
630            console.info('value:' + value + 'mode:' + mode.toString())
631          })
632        Text(this.outSetValueTwo.toFixed(0)).fontSize(12)
633      }
634      .width('80%')
635
636      Text('inset slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)
637      Row() {
638        Slider({
639          value: this.inSetValueOne,
640          min: 0,
641          max: 100,
642          style: SliderStyle.InSet
643        })
644          .blockColor('#191970')
645          .trackColor('#ADD8E6')
646          .selectedColor('#4169E1')
647          .showTips(true)
648          .onChange((value: number, mode: SliderChangeMode) => {
649            this.inSetValueOne = value
650            console.info('value:' + value + 'mode:' + mode.toString())
651          })
652        Text(this.inSetValueOne.toFixed(0)).fontSize(12)
653      }
654      .width('80%')
655      Row() {
656        Slider({
657          value: this.inSetValueTwo,
658          step: 10,
659          style: SliderStyle.InSet
660        })
661          .blockColor('#191970')
662          .trackColor('#ADD8E6')
663          .selectedColor('#4169E1')
664          .showSteps(true)
665          .onChange((value: number, mode: SliderChangeMode) => {
666            this.inSetValueTwo = value
667            console.info('value:' + value + 'mode:' + mode.toString())
668          })
669        Text(this.inSetValueTwo.toFixed(0)).fontSize(12)
670      }
671      .width('80%')
672
673      Text('none slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)
674      Row() {
675        Slider({
676          value: this.noneValueOne,
677          min: 0,
678          max: 100,
679          style: SliderStyle.NONE
680        })
681          .blockColor('#191970')
682          .trackColor('#ADD8E6')
683          .selectedColor('#4169E1')
684          .showTips(true)
685          .onChange((value: number, mode: SliderChangeMode) => {
686            this.noneValueOne = value
687            console.info('value:' + value + 'mode:' + mode.toString())
688          })
689        Text(this.noneValueOne.toFixed(0)).fontSize(12)
690      }
691      .width('80%')
692
693      Row() {
694        Column() {
695          Text('vertical outset slider').fontSize(9).fontColor(0xCCCCCC).width('50%').margin(15)
696          Row() {
697            Text().width('10%')
698            Slider({
699              value: this.vOutSetValueOne,
700              style: SliderStyle.OutSet,
701              direction: Axis.Vertical
702            })
703              .blockColor('#191970')
704              .trackColor('#ADD8E6')
705              .selectedColor('#4169E1')
706              .showTips(true)
707              .onChange((value: number, mode: SliderChangeMode) => {
708                this.vOutSetValueOne = value
709                console.info('value:' + value + 'mode:' + mode.toString())
710              })
711            Slider({
712              value: this.vOutSetValueTwo,
713              step: 10,
714              style: SliderStyle.OutSet,
715              direction: Axis.Vertical
716            })
717              .blockColor('#191970')
718              .trackColor('#ADD8E6')
719              .selectedColor('#4169E1')
720              .showSteps(true)
721              .onChange((value: number, mode: SliderChangeMode) => {
722                this.vOutSetValueTwo = value
723                console.info('value:' + value + 'mode:' + mode.toString())
724              })
725          }
726        }.width('50%').height(300)
727
728        Column() {
729          Text('vertical inset slider').fontSize(9).fontColor(0xCCCCCC).width('50%').margin(15)
730          Row() {
731            Slider({
732              value: this.vInSetValueOne,
733              style: SliderStyle.InSet,
734              direction: Axis.Vertical,
735              reverse: true // By default, at the top of the vertical slider is the min value and at the bottom is the max value. Therefore, if you want to slide from bottom to top, set reverse to true.
736            })
737              .showTips(true)
738              .onChange((value: number, mode: SliderChangeMode) => {
739                this.vInSetValueOne = value
740                console.info('value:' + value + 'mode:' + mode.toString())
741              })
742            Slider({
743              value: this.vInSetValueTwo,
744              step: 10,
745              style: SliderStyle.InSet,
746              direction: Axis.Vertical,
747              reverse: true
748            })
749              .showSteps(true)
750              .onChange((value: number, mode: SliderChangeMode) => {
751                this.vInSetValueTwo = value
752                console.info('value:' + value + 'mode:' + mode.toString())
753              })
754          }
755        }.width('50%').height(300)
756      }
757    }.width('100%')
758  }
759}
760```
761
762![slider](figures/slider.gif)
763
764### Example 2: Using Custom Slider Styles
765
766This example demonstrates how to customize the slider styles by setting **blockBorderColor**, **blockSize**, **blockBorderWidth**, and **blockStyle** for the slider block, **stepSize** and **stepColor** for the step, **trackBorderRadius** for the track's corner radius, and **selectedBorderRadius** for the selected part's corner radius.
767
768```ts
769@Entry
770@Component
771struct SliderExample {
772  @State tipsValue: number = 40
773
774  build() {
775    Column({ space: 8 }) {
776      Text('block').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
777      Slider({ style: SliderStyle.OutSet, value: 40 })
778        .blockSize({ width: 40, height: 40 })
779        .blockBorderColor(Color.Red)
780        .blockBorderWidth(5)
781      Divider()
782      Text('step').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
783      Slider({ style: SliderStyle.InSet, value: 40, step: 10 })
784        .showSteps(true)
785        .stepSize(8)
786        .stepColor(Color.Yellow)
787      Divider()
788      Text('track').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
789      Slider({ style: SliderStyle.InSet, value: 40 })
790        .trackBorderRadius(2)
791      Divider()
792      Text('selected').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
793      Slider({ style: SliderStyle.InSet, value: 40 })
794        .selectedBorderRadius(2)
795      Divider()
796      Text('blockStyle').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
797      Slider({ style: SliderStyle.OutSet, value: 40 })
798        .blockStyle({ type: SliderBlockType.DEFAULT })
799      Slider({ style: SliderStyle.OutSet, value: 40 })
800        .blockStyle({ type: SliderBlockType.IMAGE, image: $r('sys.media.ohos_app_icon') })
801      Slider({ style: SliderStyle.OutSet, value: 40 })
802        .blockSize({ width: '60px', height: '60px' })
803        .blockColor(Color.Red)
804        .blockStyle({ type: SliderBlockType.SHAPE, shape: new Path({ commands: 'M60 60 M30 30 L15 56 L45 56 Z' }) })
805      Divider()
806      Text('tips').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
807      Slider({ style: SliderStyle.InSet, value: this.tipsValue })
808        .showTips(true, this.tipsValue.toFixed())
809        .onChange(value => {
810          this.tipsValue = value
811        })
812    }
813  }
814}
815```
816
817![slider_2](figures/slider_2.png)
818
819
820
821### Example 3: Customizing the Slider
822
823This example demonstrates how to customize the **Slider** component using a style builder to define the content area. Clicking the increase button will increment the progress bar by the step size set in the original **Slider** component, and clicking the decrease button will decrement the progress bar, triggering the **onChange** event of the original component.
824
825```ts
826// xxx.ets
827
828@Builder function buildSlider(config: SliderConfiguration) {
829  Row() {
830    Column({space: 30}) {
831      Progress({value: config.value, total: config.max, type:ProgressType.Ring})
832        .margin({ top:20 })
833
834      Button('Increase').onClick(() => {
835        config.value = config.value + config.step
836        config.triggerChange(config.value, SliderChangeMode.Click)
837      })
838        .width(100)
839        .height(25)
840        .fontSize(10)
841        .enabled(config.value<config.max)
842
843      Button('Decrease').onClick(() => {
844        config.value=config.value-config.step
845        config.triggerChange(config.value, SliderChangeMode.Click)
846      })
847        .width(100)
848        .height(25)
849        .fontSize(10)
850        .enabled(config.value>config.min)
851
852      Slider({
853        value: config.value,
854        min: config.min,
855        max: config.max,
856        step:config.step,
857      })
858        .width(config.max)
859        .visibility((config.contentModifier as MySliderStyle).showSlider?Visibility.Visible:Visibility.Hidden)
860        .showSteps(true)
861        .onChange((value: number, mode: SliderChangeMode) => {
862          config.triggerChange(value, mode)
863        })
864      Text('Current state: '+ ((config.contentModifier as MySliderStyle).sliderChangeMode==0?"Begin"
865        :((config.contentModifier as MySliderStyle).sliderChangeMode==1?"Moving"
866          :((config.contentModifier as MySliderStyle).sliderChangeMode==2?"End"
867            :((config.contentModifier as MySliderStyle).sliderChangeMode==3?"Click":"None")))))
868        .fontSize(10)
869      Text('Progress: '+ config.value)
870        .fontSize(10)
871      Text('Min: ' + config.min)
872        .fontSize(10)
873      Text('Max: ' + config.max)
874        .fontSize(10)
875      Text('Step: ' + config.step)
876        .fontSize(10)
877    }
878    .width('80%')
879
880  }
881  .width('100%')
882}
883
884class MySliderStyle implements ContentModifier<SliderConfiguration> {
885  showSlider:boolean=true
886  sliderChangeMode:number=0
887  constructor(showSlider: boolean,sliderChangeMode:number) {
888    this.showSlider = showSlider
889    this.sliderChangeMode = sliderChangeMode
890  }
891  applyContent() : WrappedBuilder<[SliderConfiguration]> {
892    return wrapBuilder(buildSlider)
893  }
894}
895
896
897@Entry
898@Component
899struct SliderExample {
900  @State showSlider:boolean=true
901  @State sliderValue: number = 0
902  @State sliderMin: number = 10
903  @State sliderMax: number = 100
904  @State sliderStep: number = 20
905  @State sliderChangeMode: number = 0
906
907  build() {
908    Column({ space: 8 }) {
909
910      Row() {
911        Slider({
912          value: this.sliderValue,
913          min: this.sliderMin,
914          max: this.sliderMax,
915          step:this.sliderStep,
916        })
917          .showSteps(true)
918          .onChange((value: number, mode: SliderChangeMode) => {
919            this.sliderValue = value
920            this.sliderChangeMode=mode
921            console.info(' [SliderLog] value:' + value + 'mode:' + mode.toString())
922          })
923          .contentModifier(new MySliderStyle(this.showSlider,this.sliderChangeMode))
924
925      }
926      .width('100%')
927
928    }.width('100%')
929  }
930}
931```
932
933![slider_3](figures/slider_builder.gif)
934