# Slider

A single or multi-thumb numeric range control.

Use Slider to adjust a numeric value or select a range. Compose a label, value output, control, track, indicator, and one thumb per selected value.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/slider">Base UI Slider</a> for upstream
  behavior and configuration. Zenos owns the public API, styling, and composition shown on this
  page.
</p>

```tsx
import { Slider } from "@zentara-co/zenos-ui";

function SliderExample() {
  return (
    <Slider.Root defaultValue={40} className="w-full max-w-sm">
      <div className="flex justify-between">
        <Slider.Label>Volume</Slider.Label>
        <Slider.Value />
      </div>
      <Slider.Control>
        <Slider.Track>
          <Slider.Indicator />
          <Slider.Thumb showTooltip />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}
```

## Import

```tsx
import { Slider } from "@zentara-co/zenos-ui";
```

## Range

Pass an array with one value per thumb to select a range. Give each thumb a distinct accessible label, and use `minStepsBetweenValues` when the values must keep a minimum distance.

```tsx
import { Slider } from "@zentara-co/zenos-ui";

function SliderRangeExample() {
  return (
    <Slider.Root
      defaultValue={[20, 80]}
      min={0}
      max={100}
      step={5}
      minStepsBetweenValues={2}
      className="w-full max-w-md"
    >
      <div className="flex justify-between gap-4">
        <Slider.Label>Risk score range</Slider.Label>
        <Slider.Value>{(_, values) => `${values[0]}–${values[1]}`}</Slider.Value>
      </div>
      <Slider.Control>
        <Slider.Track>
          <Slider.Indicator />
          <Slider.Thumb index={0} aria-label="Minimum risk score" />
          <Slider.Thumb index={1} aria-label="Maximum risk score" />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}
```

## Hover, pressed, and focus states

Hovering a thumb reveals a subtle halo at 20% opacity. Pressing or dragging uses a stronger layer at 30% opacity around the active thumb, while keyboard focus retains a distinct focus ring. The halo sits outside the thumb so its border remains intact; it does not change the thumb's position or track dimensions. Disabled thumbs do not show interaction layers, and reduced-motion preferences disable their transitions.

## Value tooltip

Each `Slider.Thumb` shows its current value in a tooltip while it is being dragged or adjusted with the keyboard. Range sliders show the value for each active thumb independently. Set `showTooltip={false}` on a thumb when the value is already communicated clearly beside the control or when a custom presentation replaces it.

## Controlled value

`onValueChange` runs continuously during interaction. Use `onValueCommitted` for work that should happen after a pointer or keyboard change finishes, such as persisting settings or requesting filtered data.

```tsx
import { Slider, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

function SliderControlledExample() {
  const [value, setValue] = useState(35);
  const [savedValue, setSavedValue] = useState(35);

  return (
    <Stack gap="3" className="w-full max-w-md">
      <Slider.Root
        value={value}
        min={0}
        max={100}
        step={5}
        onValueChange={(next) => typeof next === "number" && setValue(next)}
        onValueCommitted={(next) => typeof next === "number" && setSavedValue(next)}
      >
        <div className="flex justify-between gap-4">
          <Slider.Label>Alert threshold</Slider.Label>
          <Slider.Value>{(_, values) => `${values[0]}%`}</Slider.Value>
        </div>
        <Slider.Control>
          <Slider.Track>
            <Slider.Indicator />
            <Slider.Thumb />
          </Slider.Track>
        </Slider.Control>
      </Slider.Root>
      <Text size="s" color="subtle" aria-live="polite">
        Committed threshold: {savedValue}%
      </Text>
    </Stack>
  );
}
```

## Orientation

Set `orientation="vertical"` on the root. The track stays narrow and centered, and the indicator grows upward from the minimum value at the bottom. Vertical sliders use the same parts and value model as horizontal sliders.

`Slider.Control` defaults to 160px tall. Change its length with an orientation-specific class such as `data-[orientation=vertical]:h-48`; the second slider below uses a 192px control. Apply thickness overrides to `Slider.Track` with `data-[orientation=vertical]:w-2` rather than changing its height. Leave thumb positioning to Base UI.

```tsx
import { Slider, Stack } from "@zentara-co/zenos-ui";

function SliderOrientationExample() {
  return (
    <Stack direction="row" gap="10" align="center" justify="center" className="w-full">
      <Slider.Root defaultValue={30} orientation="vertical">
        <Slider.Label>Low</Slider.Label>
        <Slider.Control>
          <Slider.Track>
            <Slider.Indicator />
            <Slider.Thumb />
          </Slider.Track>
        </Slider.Control>
        <Slider.Value />
      </Slider.Root>
      <Slider.Root defaultValue={70} orientation="vertical">
        <Slider.Label>High</Slider.Label>
        <Slider.Control className="data-[orientation=vertical]:h-48">
          <Slider.Track>
            <Slider.Indicator />
            <Slider.Thumb />
          </Slider.Track>
        </Slider.Control>
        <Slider.Value />
      </Slider.Root>
    </Stack>
  );
}
```

## Custom styling

Each part accepts the usual `className` prop; you do not need a variant or color prop. Style the root's spacing, the control's hit area, the track's thickness, the indicator's fill, and the thumb independently. Include matching `dark:` overrides when replacing built-in dark-theme colors.

The thumb's `before` pseudo-element draws the value tooltip, while `after` draws the interaction halo. Override the halo's border color for hover, `active`, and the focused thumb's `data-[dragging]` state to match your palette. Keep both layers non-interactive, preserve visible keyboard focus, and avoid replacing Base UI's inline thumb positioning. The custom example disables the built-in tooltip before applying its own thumb treatment.

```tsx
import { Slider } from "@zentara-co/zenos-ui";

function SliderCustomExample() {
  return (
    <Slider.Root defaultValue={60} step={5} className="w-full max-w-md gap-3">
      <div className="flex justify-between gap-4">
        <Slider.Label>Playback speed</Slider.Label>
        <Slider.Value>{(_, values) => `${values[0]}%`}</Slider.Value>
      </div>
      <Slider.Control className="py-3">
        <Slider.Track className="h-2 bg-background-accent-purple-subtlest-default dark:bg-background-accent-purple-subtlest-default">
          <Slider.Indicator className="bg-background-accent-purple-bolder-default dark:bg-background-accent-purple-bolder-default" />
          <Slider.Thumb
            showTooltip={false}
            className="size-5 border-border-accent-purple-default dark:border-border-accent-purple-default after:border-background-accent-purple-subtlest-hover active:after:border-background-accent-purple-subtlest-pressed data-[dragging]:has-[:focus]:after:border-background-accent-purple-subtlest-pressed"
          />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}
```

## Disabled

Disable the root to prevent pointer and keyboard changes across every thumb. The track and indicator are subdued. The thumb keeps an opaque inner fill so the track does not show through it, while its border uses 50% opacity. Keep explanatory text available when users need to understand why a setting cannot be changed.

```tsx
import { Slider, Text } from "@zentara-co/zenos-ui";

function SliderDisabledExample() {
  return (
    <Slider.Root defaultValue={65} disabled className="w-full max-w-md">
      <div className="flex justify-between gap-4">
        <Slider.Label>Managed retention</Slider.Label>
        <Slider.Value>{(_, values) => `${values[0]} days`}</Slider.Value>
      </div>
      <Slider.Control>
        <Slider.Track>
          <Slider.Indicator />
          <Slider.Thumb />
        </Slider.Track>
      </Slider.Control>
      <Text size="s" color="subtle">
        Retention is managed by your organization.
      </Text>
    </Slider.Root>
  );
}
```

## Anatomy

```text
Slider.Root
Slider.Label
Slider.Value
Slider.Control
Slider.Track
Slider.Indicator
Slider.Thumb
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| value | number \| readonly number[] | — | Controlled single value or range values. |
| defaultValue | number \| readonly number[] | — | Initial uncontrolled single value or range values. |
| onValueChange | (value, eventDetails) => void | — | Runs during interaction. |
| onValueCommitted | (value, eventDetails) => void | — | Runs after an interaction commits a changed value. |
| min / max / step | number | 0 / 100 / 1 | Numeric bounds and increment. |
| largeStep | number | 10 | Increment used by Page Up, Page Down, and modified arrow keys. |
| minStepsBetweenValues | number | 0 | Minimum step distance maintained between range thumbs. |
| orientation | horizontal \| vertical | horizontal | Slider axis. Vertical controls default to 160px tall with a narrow, centered track; customize height on Slider.Control. |
| disabled | boolean | false | Disables all thumbs. |
| name / form | string | — | Native form ownership and submission metadata. |
| format / locale | Intl.NumberFormatOptions / Intl.LocalesArgument | — | Formats the displayed and accessible numeric value. |
| Thumb.showTooltip | boolean | true | Shows the active thumb value while dragging or using the keyboard. |
| className | string | — | Each part accepts custom styling. Apply track thickness, indicator fill, and thumb or state-layer overrides to the corresponding part. |
| native props | React.Base UI Slider props | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

`Slider.Label` names a single-thumb slider automatically. Name every thumb separately in a range. Arrow keys change by `step`; Page Up and Page Down use `largeStep`; Home and End move to the minimum and maximum. In vertical orientation, Up increases the value and Down decreases it, and the native range input exposes `aria-orientation="vertical"`.

Visible focus remains on the active thumb, and disabled thumbs are removed from interaction. Use labels and value outputs to communicate the setting rather than relying on track color. Preserve native keyboard behavior and sufficient contrast when applying custom styles.

Source: https://zenos-ui.pages.dev/components/slider/