Slider
Sliders allow users to select from a range of values.
Usage
Import the component:
import 'mdui/components/slider.js';
Import the TypeScript type:
import type { Slider } from 'mdui/components/slider.js';
Example:
<mdui-slider></mdui-slider>Disabled State
Add the disabled attribute to disable the slider.
Range
Use the min and max attributes to set the slider's minimum and maximum values.
Step Interval
Use the step attribute to set the slider's step interval.
Tickmarks
Add the tickmarks attribute to show tickmarks on the slider.
Hide Value Label
Add the nolabel attribute to hide the value label.
Customize Value Label
The labelFormatter property lets you customize the value label's display format. It takes the slider's current value and returns the text to display.
API
Properties
| Attribute | Property | Reflect | Type | Default |
|---|---|---|---|---|
value | value | number | 0 | |
The value of the slider, which is submitted with form data. | ||||
defaultValue | number | 0 | ||
The default value. The slider resets to this value when the form is reset. JavaScript only. | ||||
autofocus | autofocus | boolean | false | |
Whether the element is focused when the page loads. | ||||
tabindex | tabIndex | number | - | |
The element's tab order when navigating with the Tab key. | ||||
min | min | number | 0 | |
Specifies the minimum value. Default is | ||||
max | max | number | 100 | |
Specifies the maximum value. Default is | ||||
step | step | number | 1 | |
Specifies the step interval. Default is | ||||
tickmarks | tickmarks | boolean | false | |
Adds tickmarks to the slider. | ||||
nolabel | nolabel | boolean | false | |
Hides the value label. | ||||
disabled | disabled | boolean | false | |
Disables the slider. | ||||
form | form | string | - | |
Associates the slider with a This lets the slider work with any form in the document, not just the one it is nested in. | ||||
name | name | string | '' | |
Specifies the slider's name, which is submitted with form data. | ||||
validity | ValidityState | - | ||
A | ||||
validationMessage | string | - | ||
Validation message. Empty string when valid. | ||||
labelFormatter | (value: number) => string | - | ||
Specifies a function to format the tooltip's value. The function receives the slider's value as an argument and should return a string to display in the tooltip. | ||||
Methods
| Name | Parameters | Returns |
|---|---|---|
click | void | |
Simulates a mouse click on the element. | ||
focus |
| void |
Sets focus on the element. An optional object parameter may include a | ||
blur | void | |
Removes focus from the element. | ||
checkValidity | boolean | |
Checks the validity of the form field. If it is invalid, it triggers an | ||
reportValidity | boolean | |
Checks the validity of the form field. If it is invalid, it triggers an | ||
setCustomValidity |
| void |
Sets a custom error message. If the message is non-empty, the field is considered invalid. | ||
CSS Parts
| Name |
|---|
track-inactive |
Inactive track. |
track-active |
Active track. |
handle |
Slider handle. |
label |
Value label. |
tickmark |
Tick mark. |