Skip to content
Get started

Components

Slider

Unstable: a value in a range on a native range input, its name and value written out above the track. Import it from @nizivo/react/unstable/slider.

Tier: clientUnstable

Examples

Basic

A slider: the name and the value above the track, the value always written out.

import type { JSX } from 'react';
import { Slider } from '@nizivo/react/unstable/slider';

export function SliderExample(): JSX.Element {
  return (
    <div style={{ display: 'grid', gap: 24, inlineSize: 320 }}>
      <Slider label="Discount" defaultValue={30} format={{ style: 'unit', unit: 'percent' }} />
      <Slider label="Volume" defaultValue={70} disabled />
    </div>
  );
}

Import

import { Slider } from '@nizivo/react/unstable/slider';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/slider.css';

Static or interactive

Client. It holds the value; the input is the browser's own <input type="range">, so its role, keys (the arrows step, Page Up and Page Down jump, Home and End go to the ends) and form submission are native. How to choose.

Value

value, defaultValue and onValueChange hold the number; min, max and step set the range, and keyStep makes the arrow keys move further than one step (a media scrubber steps 1 second and seeks 5). The value is always written out above the track: format (Intl number options) or valueText (a function) gives the words, which a screen reader hears as aria-valuetext ("30%"). label names it, or aria-label when there is no visible name.

Fill

The fill is drawn from a custom property set when the slider hydrates (no style attribute, so it works under a strict CSP); Firefox draws its own. Before hydration the track shows no fill.

Props

Client component Renders data-slot="slider" with the class nz-slider. Props: SliderProps. Source: src/unstable/slider/slider.client.tsx.

NameTypeDefaultDescription
aria-labelstring–

Names the input when there is no label.

defaultValuenumbermin

The value at first (uncontrolled).

disabledbooleanfalse
formatIntl.NumberFormatOptions–

Number format for the default value text.

keyStepnumberstep

How far the arrow keys move it, when not one step: a media scrubber steps 1 second and seeks 5. Page Up, Page Down, Home and End stay the browser's.

labelReactNode–

The visible name. Without it, name the slider with aria-label.

localestring'en-US'

BCP 47 tag for the default value text.

maxnumber100
minnumber0
namestring–

The input's name, for a form that posts it.

onValueChange(value: number) => void–
renderRenderProp<SliderState>–

Must render a <div>.

showValuebooleantrue

Shows the value text above the track.

stepnumber1
valuenumber–

The value (controlled).

valueText(value: number) => stringthe number, formatted

The value in words, shown above the track and read by a screen reader.

  • Also takes every attribute of <div> except children, defaultValue, onChange; aria-label is redeclared above. (Omit<ComponentPropsWithRef<"div">, "defaultValue" | "onChange" | "children">)

render takes an element, or, in client code, a function of the props and this state (SliderState):

NameTypeDefaultDescription
disabledrequiredboolean–
valuerequirednumber–

Other exports

SliderProps type

import type { SliderProps } from '@nizivo/react/unstable/slider'

The props of Slider, listed above.

SliderState type

import type { SliderState } from '@nizivo/react/unstable/slider'

The render state of Slider, listed above.

Data attributes and slots

Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.

SlotRendered byData attributes
slider
.nz-slider
Slider
root (takes render)
  • data-disabled (present or absent) ← disabled
    Mirrors the disabled attribute
slider-input
.nz-slider-input
Slider
inner element (CSS only); interactive, focus: self
none
slider-label
.nz-slider-label
Slider
inner element (CSS only)
none
slider-value
.nz-slider-value
Slider
inner element (CSS only)
none

CSS hooks

Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.

This stylesheet reads no public hook.

Layers: nz.components. Classes: .nz-slider, .nz-slider-input, .nz-slider-label, .nz-slider-top, .nz-slider-value.

Tokens this stylesheet reads (11)

--nz-bg-brand, --nz-chart-track, --nz-font-label-m, --nz-radius-full, --nz-space-1, --nz-space-2, --nz-space-3, --nz-space-5, --nz-space-6, --nz-text-primary, --nz-text-secondary

Accessibility

These parts are interactive. Each gets the focus outline and touch-action rule from @nizivo/react/css/base.css (the nz.base layer), so the floor survives a restyle:

  • slider-input: draws the focus outline itself on keyboard focus.

Keyboard

To be written.

On this page