Slider
An input where the user selects a value from within a given range.
Slider is a control for a numeric value within a range (volume, opacity, price). Drag the knob or click the track to set the value. The range is fixed: 0 to 100, in steps of 1.
Installation
$ bext ui add slider
Copy and paste the following into src/components/ui/slider.tsx.
This component is interactive. Make sure the shared island is loaded (see Islands). It reacts to data-ui="slider" hooks.
Usage
Anatomy
<Slider value={50} label="Volume" />API Reference
Slider
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | 50 | Initial position, from 0 to 100. Values outside the range are clamped. |
| label | string | "Value" | aria-label of the thumb. |
| className | string | — | Extra classes on the root, for example a width. |
Data Attributes
Attributes you can target in custom CSS to override the style for each state.
| Attribute | On | Values | Description |
|---|---|---|---|
| data-ui="slider" | root | — | The island handles mouse and touch dragging and the keyboard. |
| data-value | root | 0..100 | Current value, rounded. Read it from your own script to use the value. |
| data-ui="slider-range" | filled part of the track | — | Its width follows the value. |
| data-ui="slider-thumb" | thumb | — | Focusable element with role="slider"; aria-valuenow follows the value. |
Keyboard
| Key | Action |
|---|---|
| Arrow Right / Arrow Up | Increase by 1 (by 10 with Shift). |
| Arrow Left / Arrow Down | Decrease by 1 (by 10 with Shift). |
| Page Up / Page Down | Increase / decrease by 10. |
| Home / End | Go to 0 / 100. |
Accessibility
The thumb sets role="slider", aria-orientation="horizontal", aria-valuemin="0", aria-valuemax="100" and aria-valuenow, which the island updates as the value changes. It is focusable (tabindex="0"). Its accessible name is the label prop: set it, because the default is the generic "Value".
The slider renders no form field: read data-value on the root from your own script if you need to submit it.
Edit this component live in the bext playground. The PRISM + signals version is the bext-native idiom: fine-grained reactivity, no virtual DOM.
On This Page