<wa-slider>
Ranges allow the user to select a single value within a given range using a slider.
<wa-slider></wa-slider>
This component works with standard <form>
elements. Please refer to the section on form controls to learn more about form submission and client-side validation.
Use the label
attribute to give the range an accessible label. For labels that contain HTML, use the label
slot instead.
<wa-slider label="Volume" min="0" max="100"></wa-slider>
Add descriptive hint to a range with the hint
attribute. For hints that contain HTML, use the hint
slot instead.
<wa-slider label="Volume" hint="Controls the volume of the current song." min="0" max="100"></wa-slider>
Use the min
and max
attributes to set the range's minimum and maximum values, respectively. The step
attribute determines the value's interval when increasing and decreasing.
<wa-slider min="0" max="10" step="1"></wa-slider>
Use the disabled
attribute to disable a slider.
<wa-slider disabled></wa-slider>
By default, the tooltip is shown on top. Set tooltip
to bottom
to show it below the slider.
<wa-slider tooltip="bottom"></wa-slider>
To disable the tooltip, set tooltip
to none
.
<wa-slider tooltip="none"></wa-slider>
You can customize the active and inactive portions of the track using the --track-color-active
and --track-color-inactive
custom properties.
<wa-slider style=" --track-color-active: var(--wa-color-brand-fill-loud); --track-color-inactive: var(--wa-color-brand-fill-normal); " ></wa-slider>
You can customize the initial offset of the active track using the --track-active-offset
custom property.
<wa-slider min="-100" max="100" style=" --track-color-active: var(--wa-color-brand-fill-loud); --track-color-inactive: var(--wa-color-brand-fill-normal); --track-active-offset: 50%; " ></wa-slider>
You can change the tooltip's content by setting the tooltipFormatter
property to a function that accepts the range's value as an argument.
<wa-slider min="0" max="100" step="1" class="range-with-custom-formatter"></wa-slider> <script> const range = document.querySelector('.range-with-custom-formatter'); range.tooltipFormatter = value => `Total - ${value}%`; </script>
The component adapts to right-to-left (RTL) languages as you would expect.
<wa-slider dir="rtl" label="مقدار" hint="التحكم في مستوى صوت الأغنية الحالية." style="--track-color-active: var(--wa-color-brand-fill-loud)" value="10"></wa-slider>
Learn more about using slots.
Name | Description |
---|---|
label
|
The slider label. Alternatively, you can use the label attribute. |
hint
|
Text that describes how to use the input. Alternatively, you can use the hint attribute. |
Learn more about attributes and properties.
Name | Description | Reflects | |
---|---|---|---|
name name |
The name of the slider, submitted as a name/value pair with form data.
Type
string Default
'' |
||
defaultValue value |
The default value of the form control. Primarily used for resetting the form control.
Type
number |
|
|
value |
The current value of the slider, submitted as a name/value pair with form data.
Type
number |
||
label label |
The slider label. If you need to display HTML, use the
label slot instead.Type
string Default
'' |
||
hint hint |
The slider hint. If you need to display HTML, use the hint slot instead.
Type
string Default
'' |
||
disabled disabled |
Disables the slider.
Type
boolean Default
false |
||
min min |
The minimum acceptable value of the slider.
Type
number Default
0 |
||
max max |
The maximum acceptable value of the slider.
Type
number Default
100 |
||
step step |
The interval at which the slider will increase and decrease.
Type
number Default
1 |
||
tooltip tooltip |
The preferred placement of the slider tooltip.
Type
'top' | 'bottom' | 'none' Default
'top' |
||
tooltipFormatter |
A function used to format the tooltip's value. The slider value is passed as the first and only argument. The
function should return a string to display in the tooltip.
Type
(value: number) => string |
||
form form |
By default, form controls are associated with the nearest containing
<form> element. This attribute allows you
to place the form control outside of a form and associate it with the form that has this id . The form must be in
the same document or shadow root for this to work.Type
string | null Default
null |
|
|
withLabel with-label |
Used for SSR to render slotted labels. If true, will render slotted label content on first paint.
Type
boolean Default
false |
|
|
withHint with-hint |
Used for SSR to render slotted labels. If true, will render slotted hint content on first paint.
Type
boolean Default
false |
|
Learn more about methods.
Name | Description | Arguments |
---|---|---|
focus() |
Sets focus on the slider. |
options: FocusOptions
|
blur() |
Removes focus from the slider. | |
stepUp() |
Increments the value of the slider by the value of the step attribute. | |
stepDown() |
Decrements the value of the slider by the value of the step attribute. |
Learn more about events.
Name | Description |
---|---|
wa-blur |
Emitted when the control loses focus. |
wa-change |
Emitted when an alteration to the control's value is committed by the user. |
wa-focus |
Emitted when the control gains focus. |
wa-input |
Emitted when the control receives input. |
wa-invalid |
Emitted when the form control has been checked for validity and its constraints aren't satisfied. |
Learn more about CSS custom properties.
Name | Description |
---|---|
--thumb-color |
The color of the thumb.
|
--thumb-gap |
The visual gap between the edges of the thumb and the track.
|
--thumb-shadow |
The shadow effects around the edges of the thumb.
|
--thumb-size |
The size of the thumb.
|
--tooltip-offset |
The vertical distance the tooltip is offset from the thumb.
|
--track-color-active |
The color of the portion of the track that represents the current value.
|
--track-color-inactive |
The of the portion of the track that represents the remaining value.
|
--track-height |
The height of the track.
|
--track-active-offset |
The point of origin of the active track.
|
Learn more about CSS parts.
Name | Description |
---|---|
form-control |
The form control that wraps the label, input, and hint. |
form-control-label |
The input's label. |
form-control-input |
The input's wrapper. |
hint |
The hint's wrapper. |
base |
The internal <input> element. |
tooltip |
The slider tooltip. |
The autoloader is the recommended way to import components. If you prefer to do it manually, use one of the following code snippets.
To manually import this component from the CDN, use the following code.
import 'https://early.webawesome.com/webawesome@3.0.0-alpha.9/dist/components/slider/slider.js';