Slider
Sliders provide a way for 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
The disabled
attribute can be used to disable the slider.
Range
The min
and max
attributes allow you to set the slider's minimum and maximum values.
Step Interval
The step
attribute allows you to set the slider's step interval.
Tickmarks
The tickmarks
attribute can be used to add tickmarks to the slider.
Hide Tooltip
The nolabel
attribute can be used to hide the slider's tooltip.
Modify Tooltip
The labelFormatter
property allows you to modify the tooltip's display format. This property is a function that takes the slider's current value as a parameter and returns the display text.
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. This can only be set via a JavaScript property. | ||||
autofocus | autofocus | boolean | false | |
Determines if the element should be focused when the page loads. | ||||
tabindex | tabIndex | number | - | |
Specifies the order in which the element receives focus 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 tooltip. | ||||
disabled | disabled | boolean | false | |
Disables the slider. | ||||
form | form | string | - | |
Associates the slider with a This attribute allows slider elements to be associated with | ||||
name | name | string | '' | |
Specifies the slider's name, which is submitted with the form data. | ||||
validity | ValidityState | - | ||
A | ||||
validationMessage | string | - | ||
The element's validation message. This is empty if the element meets its constraints. | ||||
labelFormatter | (value: number) => string | - | ||
Specifies a function to format the tooltip's value. The function should take the slider's value as an argument and 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 parameter can be an object with a | ||
blur | void | |
Removes focus from the element. | ||
checkValidity | boolean | |
Checks the validity of the form field. If it's invalid, it triggers an | ||
reportValidity | boolean | |
Checks the validity of the form field. If it's invalid, it triggers an | ||
setCustomValidity |
| void |
Sets a custom error message. If the text is non-empty, it indicates that the field is invalid. |
CSS Parts
Name |
---|
track-inactive |
Inactive track. |
track-active |
Active track. |
handle |
Slider handle. |
label |
Prompt text. |
tickmark |
Tick mark. |