Slider

Slider lets users choose a value or range along a track.

tsx
import { Slider } from '@/components/ui/wideset/slider/Slider';

<Slider defaultValue={[40]} />

Installation

pnpm dlx wideset add slider

Copies the component and any Wideset components it uses into your project.

Examples

Types

The slider draws one thumb per value: [40] picks one value, [20, 80] picks an interval between two thumbs. Each thumb is its own stop in the tab order and moves with the arrow keys; Page Up and Page Down jump ten steps, Home and End go to the ends.

tsx
import { Slider } from '@/components/ui/wideset/slider/Slider';

export default function SliderTypes() {
  return (
    <div className="gap-ws-16 flex w-[20rem] max-w-full flex-col">
      <Slider aria-label="Volume" defaultValue={[40]} />
      <Slider thumbAriaLabels={['Minimum price', 'Maximum price']} defaultValue={[20, 80]} />
    </div>
  );
}

Labels

The slider prints no numbers itself: put a Slider.Label where the reader needs the scale. Both ends in one row is the usual choice; under the track suits a narrow row; one end alone works when the other is obvious. They are plain numbers, so still name what the slider sets in a visible label next to it.

tsx
import { Slider } from '@/components/ui/wideset/slider/Slider';

export default function SliderLabels() {
  return (
    <div className="gap-ws-16 flex w-[20rem] max-w-full flex-col">
      <div className="gap-ws-9 flex items-center">
        <Slider.Label>0</Slider.Label>
        <Slider className="min-w-0 flex-1" aria-label="Volume" defaultValue={[40]} />
        <Slider.Label>100</Slider.Label>
      </div>
      <div>
        <Slider aria-label="Brightness" defaultValue={[40]} />
        <div className="pt-ws-8 flex justify-between">
          <Slider.Label>0</Slider.Label>
          <Slider.Label>100</Slider.Label>
        </div>
      </div>
      <div className="gap-ws-9 flex items-center">
        <Slider className="min-w-0 flex-1" aria-label="Opacity" defaultValue={[40]} />
        <Slider.Label>100</Slider.Label>
      </div>
    </div>
  );
}

States

Hover, drag and focus are live; the focus ring shows only for keyboard focus. A disabled slider ignores the pointer and leaves the tab order, so say why it is locked next to it.

tsx
import { Slider } from '@/components/ui/wideset/slider/Slider';

export default function SliderStates() {
  return (
    <div className="gap-x-ws-7 gap-y-ws-16 grid w-[24rem] max-w-full grid-cols-[4rem_1fr] items-center">
      <span className="typography-caption-md text-ws-static-subtle">Default</span>
      <Slider thumbAriaLabels={['Minimum price', 'Maximum price']} defaultValue={[20, 80]} />
      <span className="typography-caption-md text-ws-static-subtle">Disabled</span>
      <Slider
        thumbAriaLabels={['Minimum price', 'Maximum price']}
        defaultValue={[20, 80]}
        disabled
      />
    </div>
  );
}

API reference

Slider

NameDescriptionDefault
aria-label

Defines a string value that labels the current element. Accessible name of the thumbs. A range prefixes it with `Minimum` / `Maximum` per thumb.

string
—
aria-labelledby

Identifies the element (or elements) that labels the current element. Id of the label that names the thumbs.

string
—
children

Content rendered inside the slider, after the thumbs.

ReactNode
—
defaultMotion

Turns the component's built-in animations on or off. When omitted, inherits the value from the nearest `MotionProvider`.

boolean
true
labels
'bottom''left''right''side'
—
showTooltipValue

Show tooltip with current value

ShowTooltipValue
—
thumbAriaLabels

Accessible name per thumb, in order, e.g. `['Minimum price', 'Maximum price']`.

string[]
—
type
'single''range'
—
Every other prop of Radix Slider.Root is passed through to it. See Radix Slider.Root.

Slider.Label

No props of its ownIt takes its content as children.
Every other prop of <span> is passed through to it. See MDN: <span>.

Accessibility

  • Always name it: aria-label, aria-labelledby, or thumbAriaLabels. There is no fallback: without one the thumb has no accessible name.
  • In a range, aria-label="price" becomes “Minimum price” / “Maximum price”; thumbAriaLabels sets each thumb’s name exactly.
  • Each thumb is its own tab stop. Arrows move one step, Page Up / Page Down ten, Home / End jump to the ends.
PartRendersDescription
SliderRadix Slider.RootA single value or range selected along a track.
Slider.Label<span>The text label associated with `Slider`.
tsx
import { Slider } from '@/components/ui/wideset/slider/Slider';

<Slider defaultValue={[40]} />

Content

Range
Value tooltip

State

Disabled