Documentation

Slider

A value or a range chosen by dragging a thumb along a track, with arrows and Page keys.

WebBetaForms

Web only — React, from @krizaka/ui/slider. Beta: its API may still change in a minor version.

When to use

  • For a value chosen by feel within bounds: volume, speed, brightness.
  • Two thumbs for a range: a price, a duration.

When not to use

  • For an exact number the user knows: an input of type number.Use instead: Field
  • For a few named options.Use instead: Radio group

Installation

Install

npm install @krizaka/ui@beta @krizaka/tailwind@beta @krizaka/tokens@beta tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Import

import { Slider } from "@krizaka/ui/slider";

Examples

Default

The thumb alone, named by label.

With a label

showLabel: the label and the formatted value above the track.

Speed

Centred

origin={0} on a ± range.

Brightness

Range

Two thumbs, each named.

Price

Disabled

Not available.

Props

A slider on one value or a range: value/defaultValue + onValueChange, min, max, step.

PropTypeDefaultDescription
labelrequiredstring—The accessible name — of the thumb, or of both thumbs of a range — passed translated.
defaultValueSliderValue—The value at first, uncontrolled: one number, or two for a range.
formatValue((value: number) => string)—The value as words (aria-valuetext) and as shown: "1.5×", "−12 %", "3 min".
onValueChange((value: V) => void)—Called on every move, with one number or two.
onValueCommit((value: V) => void)—Called once the drag or the key press ends.
originnumber—Fills from this value instead of the minimum (a ±range from 0: brightness, balance). One thumb only.
showLabelboolean—Shows the label and the value above the track. Without it, label only names the thumb.
thumbLabels[string, string]—For a range: each thumb's own name (["Minimum", "Maximum"]), passed translated.
valueSliderValue—One number (a thumb) or two (a range). Controlled with onValueChange.

Accessibility

  • Radix Slider: each thumb is a slider named by label (or thumbLabels for a range).
  • formatValue also gives aria-valuetext: the value as it is read.

Keyboard

KeysAction
Arrow keysMove by one step.
Page Up / Page DownMove by a larger step.
Home / EndGo to the minimum or the maximum.

Best practices

  • Show the value (showLabel) when it matters, formatted by formatValue.
  • Choose a step people can reach with the arrows; origin to fill from a centre on a ± range.

Generated from the code of @krizaka/ui 2.0.0-beta.6: its meta.ts, its examples and its types.Edit this documentation on GitHub

On this page