Fragiola

API: components

Slider

A number, or a range of numbers, chosen by dragging a thumb, pressing the track or with the keyboard, following the APG's slider patterns, in each framework.

Choose a number within bounds, or a range with several thumbs (WAI-ARIA APG slider and multi-thumb slider). It works in a native <form>: each thumb submits its value. A Label names it and a Value shows the value, formatted with Intl.NumberFormat when you pass format.

Volume and price
Gallery

Behaviour

  • Value: a number, or an array of numbers for several thumbs (sorted); the type of defaultValue (or value) decides. Values snap to min + n × step and stay in [min, max]; thumbs never cross, and stay minStepsBetweenValues × step apart.
  • Pointer: a press on the Control moves the nearest thumb there (reason track-press), focuses it and starts a drag; the drag follows the pointer outside the Control until it is released (reason drag, data-dragging meanwhile). touch-action: none keeps a touch drag from scrolling.
  • Commit: onValueCommit once a drag ends, or after a key changed the value.
  • Label: names the Root and every Thumb that has no aria-label or aria-labelledby of its own; a press on it focuses the first Thumb. Inside a Field, the Field's Label names the slider instead: use one or the other.
  • Value: an output whose for lists the Thumbs' ids. It shows the formatted values, joined with " – " for several thumbs, or the content you give it. aria-live="off": a drag would announce every step.
  • Format: with format (Intl.NumberFormatOptions, in locale), the Value and each Thumb's aria-valuetext use the formatted value; getAriaValueText wins over it. Without format, the Value shows the plain numbers and the Thumbs have no aria-valuetext of their own. Without locale, the runtime's default: a page rendered on a server passes locale, so the server formats as the browser does.
  • RTL: horizontal sliders run right to left (min at the right, the arrows swap), in the direction of a DirectionProvider, else the computed one.
  • Forms: one hidden input per thumb submits name=value, in order. Inside a Field, its validate receives the number (or numbers); it cannot block a native submission (the inputs are type="hidden"), a Form does.

Anatomy

partelementdata-primitives-partrole
Rootdivslider-rootthe group; holds the state
Labeldivslider-labelnames the Root and its Thumbs
Valueoutputslider-valueshows the formatted value(s)
Controldivslider-controlthe interactive area
Trackdivslider-trackthe rail
Indicatordivslider-indicatorthe filled part: from min to the value, or between two thumbs
Thumbdivslider-thumba slider; one per value
(hidden input)input type="hidden"slider-inputone per value: what the form submits

Usage

import { Slider } from "@fragiola/primitives-react/slider";

<Slider.Root
    defaultValue={[20, 80]}
    minStepsBetweenValues={10}
    name="price"
    format={{ style: "currency", currency: "EUR", maximumFractionDigits: 0 }}
    locale="de-DE"
>
    <Slider.Label>Price</Slider.Label>
    <Slider.Value />
    <Slider.Control>
        <Slider.Track>
            <Slider.Indicator />
        </Slider.Track>
        <Slider.Thumb aria-label="Minimum price" />
        <Slider.Thumb aria-label="Maximum price" />
    </Slider.Control>
</Slider.Root>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. The names below are React's; Vue binds them the same way (v-model:value, @value-commit), and Angular as inputs and outputs ([(value)], (valueCommit)).

Root

proptypedefaultdescription
valuenumber | number[]the value, controlled
defaultValuenumber | number[]minthe initial value, uncontrolled
onValueChange(value, details: { reason }) => voidevery change (keyboard, track-press, drag)
onValueCommit(value, details: { reason }) => voidonce a drag ends, or after a key
minnumber0the lower bound
maxnumber100the upper bound
stepnumber1the step of the arrows and the snapping
largeStepnumber10the step of Page Up, Page Down and Shift+Arrow
minStepsBetweenValuesnumber0the smallest distance between two thumbs, in steps
orientation"horizontal" | "vertical""horizontal"the axis
disabledbooleanfalseignores the pointer and the keys
namestringthe form name of the hidden inputs (a Field's wins)
formatIntl.NumberFormatOptionshow the Value and each Thumb's aria-valuetext write the values
localestringthe runtime'sthe locale of format (a BCP 47 tag)

Label

proptypedefaultdescription
idstringgeneratedthe id the Root's and the Thumbs' aria-labelledby point at

Value

No props of its own. Its children replace the formatted values: a function (formattedValues, values) => ReactNode in React, the default scoped slot { formattedValues, values } in Vue, the directive's formattedValues() and values() signals in Angular.

Control

No props of its own.

Track

No props of its own.

Indicator

No props of its own.

Thumb

proptypedefaultdescription
indexnumberits orderthe index of its value
getAriaValueText(value: number, index: number) => stringthe aria-valuetext; it wins over format
disabledbooleanfalsethis thumb only
idstringgeneratedthe thumb's id, in the Value's for

A thumb's accessible name comes from the consumer (aria-label, aria-labelledby), or the Label.

State and part attributes

partattributes
Rootrole="group", aria-labelledby (the Label, while one is rendered), data-orientation, data-disabled, data-dragging; in a Field, the field's states
Labelid, data-orientation, data-disabled
Valuefor (the Thumbs' ids, in value order), aria-live="off", data-orientation, data-disabled
Control, Trackdata-orientation, data-disabled, data-dragging
Indicatordata-orientation; structural inline style (inset-inline-start and inline-size in %, or the block ones)
Thumbrole="slider", id, tabindex="0", aria-valuenow, aria-valuemin, aria-valuemax (the bounds it can reach), aria-valuetext, aria-labelledby (the Label, without a name of its own), aria-orientation, aria-disabled, data-orientation, data-index, data-dragging, data-disabled; structural inline style placing it

Keyboard

keyaction
ArrowRight, ArrowUp+ step (ArrowLeft in RTL)
ArrowLeft, ArrowDown− step (ArrowRight in RTL)
Page Up / Page Down, Shift+Arrow± largeStep
Home / Endthe lowest / highest value the thumb can reach
Tabthe next thumb, in value order

Exports

entryexports
@fragiola/primitives-react/sliderChangeDetails, ChangeReason, RenderProp, Slider, SliderLabelProps, SliderRootProps, SliderState, SliderThumbProps, SliderThumbState, SliderValueProps
@fragiola/primitives-vue/sliderChangeDetails, ChangeReason, RenderSlotProps, Slider, SliderLabelProps, SliderRootEmits, SliderRootProps, SliderState, SliderThumbProps, SliderThumbState, SliderValueSlotProps, SliderValueSlots
@fragiola/primitives-angular/sliderChangeDetails, ChangeReason, SliderControl, SliderIndicator, SliderLabel, SliderRoot, SliderRootValue, SliderState, SliderThumb, SliderThumbState, SliderTrack, SliderValue, ValueChangeEvent