Slider
A single-thumb slider built on a native <input type="range"> — pointer drag,
keyboard control and form participation come from the browser.
Import
Section titled “Import”<script> import Slider from "@invisible-ui/svelte/Slider.svelte";</script><script setup> import { Slider } from "@invisible-ui/vue";</script>import { Slider } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-slider></ds-slider>In Elements, the attributes set the value and the range. The format
property turns a number into the text the readouts show, and moving the thumb
sends a bubbling change event with detail.value:
<ds-slider label="Volume" name="volume" value="40" step="10" show-value></ds-slider>| Prop | Type | Default | Description |
|---|---|---|---|
value | number | 0 | |
min | number | 0 | |
max | number | 100 | |
step | number | 1 | |
orientation | "horizontal" | "vertical" | "horizontal" | |
disabled | boolean | false | |
label * | string | — | Accessible name. |
error | string | undefined | undefined | Error message, shown under the track and announced. The input points at it through aria-describedby and takes aria-invalid. The app owns it: a form reset leaves it in place, so the app clears it. |
name | string | undefined | undefined | Form field name — the value is submitted under it. |
showValue | boolean | false | Show the current value to the side of the track. |
showRange | boolean | false | Show the min and max reference values under the ends of the track. |
ticks | boolean | false | Show tick marks at each step (only when the count is reasonable). |
format | (value: number) => string | (v) => String(v) | Format the displayed value/range (e.g. add a unit). |
onValueChange | ((value: number) => void) | undefined | undefined | Called when the value changes. |
icon | Snippet | undefined | undefined | A decorative icon before the track. |
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue | number | undefined | v-model value; takes precedence over value when bound. |
value | number | 0 | |
min | number | 0 | |
max | number | 100 | |
step | number | 1 | |
orientation | SliderOrientation | "horizontal" | |
disabled | boolean | false | |
label * | string | — | Accessible name for the slider (required). |
name | string | undefined | Form field name; the value is submitted under it. |
showValue | boolean | false | Show the current value to the side of the track. |
showRange | boolean | false | Show the min and max reference values under the ends of the track. |
ticks | boolean | false | Show tick marks at each step (drawn only when the count stays readable). |
format | (value: number) => string | (value: number) => String(value) | Format the displayed value/range (e.g. add a unit). |
error | string | undefined | Error message. When non-empty it shows after the control as an alert and describes the control. The application owns it: a form reset leaves it in place, and the application clears it. |
onValueChange | (value: number) => void | undefined | Called whenever the value changes. |
| Event | Payload |
|---|---|
update:modelValue | value: number |
Slots: icon.
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | 0 | Initial (uncontrolled) or current (controlled) value. |
min | number | 0 | |
max | number | 100 | |
step | number | 1 | |
orientation | SliderOrientation | "horizontal" | |
disabled | boolean | false | |
error | string | — | An error message shown under the control as an alert. It describes the control and marks it invalid. The app owns it: a form reset leaves it in place, so the app clears it. |
label * | string | — | Accessible name for the slider (required). |
name | string | — | Form field name; the value is submitted under it. |
showValue | boolean | false | Show the current value to the side of the track. |
showRange | boolean | false | Show the min and max reference values under the ends of the track. |
ticks | boolean | false | Show tick marks at each step (drawn only when the count stays readable). |
format | (value: number) => string | String | Format the displayed value/range (e.g. add a unit). |
onValueChange | (value: number) => void | — | Called whenever the value changes. |
icon | ReactNode | — | A decorative icon before the track. |
| Attribute | Reactive | Description |
|---|---|---|
label * | yes | the accessible name |
value | yes | 0 by default |
min | yes | 0 by default |
max | yes | 100 by default |
step | yes | 1 by default |
orientation | yes | horizontal|vertical |
disabled | yes | |
name | yes | |
show-value | yes | |
show-range | yes | |
ticks | yes | |
error | yes | a message under the slider that also marks it invalid; the page owns it, so a form reset leaves it in place |
Reactive attributes re-render the element when they change after the first render.
Properties: value (number), format ((value: number) => string).
Emits: bubbling change CustomEvent with detail.value whenever the user moves the thumb.
Error message
Section titled “Error message”A non-empty error shows the message under the control with a hazard icon and
announces it as an alert. The input points at it through aria-describedby and
takes aria-invalid="true". The message is plain text.
<Slider label="Volume" bind:value error={value === 0 ? "Choose a volume above zero." : ""} />The app owns the message and clears it: a form reset leaves it in place. In Flutter, the validator’s message clears on form reset.
Accessibility
Section titled “Accessibility”- Native
<input type="range">: the browser provides the slider role, ARIA value, Arrow/Home/End/PageUp-Down control, pointer dragging and form submission. - A non-empty
erroraddsaria-invalid="true"and anaria-describedbylink to the message on the input.
Example
Section titled “Example”<Slider value={40} step={5} label="Volume" />In React, onValueChange reports each move, and the icon prop takes the
leading glyph:
<Slider label="Volume" value={volume} showValue icon={<VolumeIcon />} onValueChange={setVolume} />Themeable via --ds-slider-*.