This documentation is under construction. Pages can be missing or change at any time. Follow it on GitHub.

Skip to content

Slider

An easily stylable range input.

Examples#

Labeling a slider#

A single-thumb slider without a visible label (such as a volume control) can be labeled using aria-label on SliderThumb. A visible label can be created using SliderLabel. For a multi-thumb range slider with a visible label, add aria-label on each SliderThumb to distinguish them.

Range slider#

To create a range slider, pass an array of values and place a SliderThumb for each value in the array, with the index of its value.

Thumbs can be configured to behave differently when they collide during pointer interactions using the thumbCollisionBehavior prop on Slider.

Steps#

Use the step prop to snap the value to multiples of a given increment, and largeStep to control the increment when using Shift + Arrow Up/Arrow Down.

Marks#

Render your own tick marks, positioning each mark along the track as a percentage of the value range.

Marks are independent of the value’s granularity—pair them with the step prop to snap the thumb to each mark.

Thumb alignment#

Set thumbAlignment="edge" to inset the thumb such that its edge aligns with the edge of the control when the value is at min or max, without overflowing the control like the default "center" alignment.

Vertical#

Set orientation to Orientation::Vertical on Slider to build a vertical slider.

Form integration#

To use a slider in a form, pass the slider name to Slider. For grouped multi-thumb range sliders in forms, Fieldset can provide the shared visible label while each thumb keeps its own aria-label.

API reference#

Import the components of the family:

use Phem\Ui\Slider;
use function Phem\Ui\{SliderLabel, SliderValue, SliderControl, SliderTrack, SliderIndicator, SliderThumb};

Slider#

A value, or a range, on a track: Base UI Slider.Root, on the phem-slider controller.

defaultValue is a number for one thumb, or a list for a range: put one SliderThumb for each value, with its index. The server render places the thumbs, so they do not move when the controller starts.

PropTypeDefault
defaultValuefloat|array0
minfloat0
maxfloat100
stepfloat1
largeStepfloat10
minStepsBetweenValuesfloat0
orientation'horizontal' | 'vertical'Orientation::Horizontal
disabledboolfalse
name?stringnull
thumbAlignmentstring'center'
thumbCollisionBehaviorstring'push'
format?arraynull
locale?stringnull
children?Htmlnull
...attrsarray[]

SliderValue#

The formatted values.

PropTypeDefault
...restmixed—

SliderControl#

The area that takes the presses and the drags.

PropTypeDefault
children?Htmlnull
...restmixed—

SliderTrack#

The bar of the slider: it holds the SliderIndicator and the SliderThumb parts.

PropTypeDefault
children?Htmlnull
...restmixed—

SliderIndicator#

The filled part of the track: from the start to the value, or between the values of a range.

PropTypeDefault
...restmixed—

SliderThumb#

A thumb, with a native range input for the keyboard, the ARIA and the form. Give it an aria-label.

PropTypeDefault
indexint0
name?stringnull
...restmixed—

SliderLabel#

The label of the slider.

PropTypeDefault
children?Htmlnull
...restmixed—

The source of the examples: examples/ui/Slider.phem.

Phem
Esc
↑↓ to navigate↵ to openEsc to close