Skip to content
Porcelana

Slider

Single or range slider with a spoken value, optional − / + buttons and thumbs that stay inside the track.

Example

Volume
Quiet hours
Example.tsx
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
import { Slider } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app root

Props

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.

PropTypeDefaultDescription
labelrequiredstring–Accessible name. Shown above the slider unless `hideLabel` is set.
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
defaultValuenumber[]–Initial value when uncontrolled.
dirDirection–Reading direction for keyboard navigation ("ltr" or "rtl").
disabledboolean–Prevents interaction and dims the control.
formstring–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.
hideLabelboolean–Keep the label for screen readers but hide it visually.
idstring–Element id. Generated automatically when omitted.
invertedboolean–Fill the track from the opposite end.
maxnumber100Highest allowed value.
minnumber0Lowest allowed value.
minStepsBetweenThumbsnumber–Minimum gap between thumbs in a range slider, in steps.
namestring–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.
orientationOrientation–Layout and arrow-key direction.
preserveThumbOrderboolean–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
showSteppersboolean–Adds − / + buttons (single-thumb sliders). They step by `stepperStep`.
showValueboolean–Show the current value next to the label.
stepnumber1Value change per arrow-key press.
stepperStepnumber–How far one − / + press moves. Defaults to step.
thumbLabelsstring[]–Labels for each thumb in a range slider, e.g. ["Minimum", "Maximum"].
valuenumber[]–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.