Documentation

Slider

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

WebBêtaFormulaires

Web uniquement — React, depuis @krizaka/ui/slider. Bêta : son API peut encore changer à une version mineure.

Quand l’utiliser

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

Quand ne pas l’utiliser

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

Installation

Installer

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

Styles

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

Importer

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

Exemples

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.

PropTypeDéfautDescription
labelrequisstring—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.

Accessibilité

  • 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.

Clavier

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

Bonnes pratiques

  • 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.

Générée depuis le code de @krizaka/ui 2.0.0-beta.6 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub

Sur cette page