Skip to content

Slider

A value chosen along a range. Pass an array and it becomes a range slider — there is no separate prop for that, because the shape of the value already says which one this is.

tsx
import { Slider } from 'neba';

<Slider label="Volume" defaultValue={65} showValue />;

Props

PropTypeDefaultDescription
sizeshared'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Height and type scale
colorshared'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info''primary'Semantic colour role. Arbitrary colour values are not accepted
orientationshared'horizontal' | 'vertical''horizontal'Which way the track runs. A vertical slider needs a height of its own
valuenumber | number[]The current value. An array gives one thumb per entry
defaultValuenumber | number[]The initial value, for an uncontrolled slider
onValueChange(value, details) => voidCalled throughout the drag
onValueCommitted(value, details) => voidCalled once, when the value settles. Put the network request here
minnumber0The lowest allowed value
maxnumber100The highest allowed value
stepnumber1The granularity the value moves in
labelReactNodeThe label above the track
descriptionReactNodeHelper text below the track
showValueboolean | ((formatted, values) => ReactNode)falseShows the current value beside the label. Pass a function to format it
disabledbooleanfalseUnavailable

onValueChange fires throughout the drag; onValueCommitted fires once, when the value settles. Put the network request on the second one.

Examples

Range

Sizes

The thumb is deliberately far larger than the track. It is the only part of the control you can actually hit, and a thumb sized to match a 6px rail is a thumb nobody catches on a touchscreen.

Vertical

A vertical slider has no length of its own — give it a height. The default is a starting point, not a rule.

The thumb does not grow

Hovering and dragging put a ring around the thumb rather than scaling it. That is the same no-transform rule the rest of the library follows, and it is not relaxed just because this particular part carries no label: a control whose parts change size under the cursor is the thing that reads as cheap.

The rail and the indicator are pills for the same reason a Switch's track is — this is a groove something travels along, not a sheet.

Accessibility

  • Each thumb is a real <input type="range">, so the arrow keys, Home/End and Page Up/Down all work without any code here.
  • label becomes the accessible name. Without one, give the slider an aria-label.
  • showValue renders an <output>, which is announced as the value changes.

Released under the MIT License