Slider
Single or range slider with a spoken value, optional − / + buttons and thumbs that stay inside the track.
Example
import { Slider } from "@porcelana/ui";
export default function Example() {
return (
<div style={{ display: "grid", gap: 24, maxWidth: 480 }}>
<Slider
label="Volume"
defaultValue={[62]}
showValue
showSteppers
stepperStep={5}
formatValue={(v) => `${v}%`}
/>
<Slider label="Quiet hours" defaultValue={[22, 80]} thumbLabels={["Start", "End"]} showValue />
</div>
);
}Import
import { Slider } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app rootProps
Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.
Slider
Radix slider with a 32px thumb inside a 44px touch target. Radix keeps thumbs in bounds, so they never overhang the track ends. Keyboard: arrows ±step, PageUp/PageDown ±10 steps, Home/End min/max.
| Prop | Type | Default | Description |
|---|---|---|---|
labelrequired | string | – | Accessible name. Shown above the slider unless `hideLabel` is set. |
aria-label | string | – | Defines a string value that labels the current element. @see aria-labelledby. |
asChild | boolean | – | Render the single child element instead, merging props and behaviour onto it. |
defaultValue | number[] | – | Initial value when uncontrolled. |
dir | Direction | – | Reading direction for keyboard navigation ("ltr" or "rtl"). |
disabled | boolean | – | Prevents interaction and dims the control. |
form | string | – | Id of the form this control belongs to. |
formatValue | ((value: number) => string) | – | Spoken value, e.g. (v) => `${v} percent`. Also used for the visible readout. |
hideLabel | boolean | – | Keep the label for screen readers but hide it visually. |
id | string | – | Element id. Generated automatically when omitted. |
inverted | boolean | – | Fill the track from the opposite end. |
max | number | 100 | Highest allowed value. |
min | number | 0 | Lowest allowed value. |
minStepsBetweenThumbs | number | – | Minimum gap between thumbs in a range slider, in steps. |
name | string | – | Field name submitted with a form. |
onValueChange | ((value: number[]) => void) | – | Called with the new value. |
onValueCommit | ((value: number[]) => void) | – | Called when the user finishes dragging or presses a key. |
orientation | Orientation | – | Layout and arrow-key direction. |
preserveThumbOrder | boolean | – | When `true`, thumbs keep their relative order and won't cross over one another while dragging. Each thumb is constrained to the values of its neighbors instead of swapping positions when dragged past them. @defaultValue false |
showSteppers | boolean | – | Adds − / + buttons (single-thumb sliders). They step by `stepperStep`. |
showValue | boolean | – | Show the current value next to the label. |
step | number | 1 | Value change per arrow-key press. |
stepperStep | number | – | How far one − / + press moves. Defaults to step. |
thumbLabels | string[] | – | Labels for each thumb in a range slider, e.g. ["Minimum", "Maximum"]. |
value | number[] | – | Controlled value. Use with onValueChange. |
Accessibility
- Each thumb is a labelled role="slider"; formatValue sets aria-valuetext ("62 percent").
- Arrows ±step, Page Up/Down ±10 steps, Home/End jump to min/max.
- Range sliders name each thumb with thumbLabels.
Mobile
- The 32px thumb has a 44px invisible touch area.
- Horizontal drags move the slider; vertical swipes still scroll the page.
- Steppers disable themselves at min and max.