antlitz
Menu

Slider

A value chosen from a range. Renders a native input type="range", so dragging, arrow keys, Home and End, and form submission all come from the platform.

import { Slider } from "antlitz";

API

PropTypeDefault
radius"none" | "sm" | "md" | "lg" | "full"none
size"sm" | "md" | "lg"md

size is antlitz's own prop, not the native size attribute, and type is fixed. Everything else is a native range input: min, max, step, value, defaultValue, disabled, name, onChange.

Usage

export function Basic() {
  return (
    <Field label="Volume">
      <Slider defaultValue={60} />
    </Field>
  );
}

A slider renders no text of its own, so give it a name — through Field, a Label, or aria-label when neither fits.

Sizes

export function Sizes() {
  return (
    <>
      <Slider size="sm" defaultValue={30} aria-label="Small" />
      <Slider size="md" defaultValue={50} aria-label="Medium" />
      <Slider size="lg" defaultValue={70} aria-label="Large" />
    </>
  );
}

Radius

export function Radius() {
  return RADII.map((radius) => (
    <Slider
      key={radius}
      radius={radius}
      defaultValue={50}
      aria-label={radius}
    />
  ));
}

Radius applies to the track and the thumb together. The default is none, like everything else in the system — a square thumb still reads as a handle, unlike a square radio, which reads as a checkbox.

Steps

export function Steps() {
  return (
    <Slider min={0} max={5} step={1} defaultValue={3} aria-label="Rating" />
  );
}

min, max and step are native. A stepped slider snaps and announces the value it landed on without any of that being implemented here.

States

export function States() {
  return (
    <>
      <Slider defaultValue={40} aria-label="Default" />
      <Slider defaultValue={40} disabled aria-label="Disabled" />
      <Slider defaultValue={40} aria-invalid aria-label="Invalid" />
    </>
  );
}

Styling a range input

The track and the thumb are engine-specific pseudo-elements — ::-webkit-slider-runnable-track, ::-moz-range-track, and their thumbs — so every rule is written twice. The component carries both sets.

No filled track

The portion before the thumb is not painted. Filling it means reading the value on every input event, which is state, and state belongs to whoever owns the value.

When that is you, a gradient gets you there:

<Slider
  value={value}
  onChange={(event) => setValue(Number(event.target.value))}
  className="[&::-webkit-slider-runnable-track]:bg-[linear-gradient(to_right,var(--color-primary)_var(--fill),var(--color-muted)_var(--fill))]"
  style={{ "--fill": `${value}%` }}
/>