Skip to content

Slider

Expressive

Chooses a value or a range on a continuous or stepped scale, in five sizes.

import { Slider, RangeSlider } from '@windmorph/react';

Props

By name or description, across the 48 props below

Slider 25 props

  • sizetype "xs" | "sm" | "md" | "lg" | "xl"default "xs"

    The track's thickness, from XS (a 16px track) to XL.

  • orientationtype "horizontal" | "vertical"default "horizontal"

    The direction the slider runs. Vertical sliders run bottom to top and default to 240px tall.

  • mintype numberdefault 0

    The lowest value.

  • maxtype numberdefault 100

    The highest value.

  • steptype numberdefault 1

    The amount the value changes by in one step.

  • tickstype booleandefault false

    Discrete: show a stop indicator at every step (use a coarse step).

  • disabledtype booleandefault false

    Turns the slider off: it can't be moved or focused.

  • valueLabeltype booleandefault false

    Show the value above the thumb while it is dragged or keyboard-focused.

  • formatOptionstype NumberFormatOptions

    Formats the value for the value indicator, and for assistive tech unless valueText says it in words.

  • valueTexttype ((value: number, index: number) => string)

    The value in words for assistive technology, each thumb's aria-valuetext, where a number format can't say it (a time: (seconds) => '1 minute 23 seconds of 10 minutes'), given the thumb's index too (0, or 1 for a range's end). Without it the value is read as formatOptions formats it; the value indicator keeps that format.

  • nametype string

    Form field name (one hidden input per thumb).

  • idtype string

    The id of the slider's root, its group (an error summary can link to it).

  • reftype Ref<HTMLDivElement>

    Ref to the root <div> element.

  • valuetype number

    The value (controlled).

  • defaultValuetype numberdefault min

    The initial value when uncontrolled.

  • centeredtype booleandefault false

    Fill the track from its centre (for values around a midpoint). M3 doesn't use inset icons on centred sliders, so leadingIcon and trailingIcon are ignored.

  • leadingIcontype ReactNode

    An icon inside the active track at its start (sizes md and up; ignored, with a dev warning, on xs and sm). When the active track is too short for it, it moves to the start of the inactive track.

  • trailingIcontype ReactNode

    An icon inside the inactive track at its end (sizes md and up; ignored on xs and sm).

Events

  • onChangetype ((value: number) => void)

    Called as the value changes, while dragging too.

  • onChangeEndtype ((value: number) => void)

    Called when the user stops dragging or releases a key.

Text

  • aria-labeltype string

    Accessible name when there's no visible label.

    One of aria-label or aria-labelledby is required.

  • aria-labelledbytype string

    The id of the visible label that names the slider.

    One of aria-label or aria-labelledby is required.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

RangeSlider 23 props

  • sizetype "xs" | "sm" | "md" | "lg" | "xl"default "xs"

    The track's thickness, from XS (a 16px track) to XL.

  • orientationtype "horizontal" | "vertical"default "horizontal"

    The direction the slider runs. Vertical sliders run bottom to top and default to 240px tall.

  • mintype numberdefault 0

    The lowest value.

  • maxtype numberdefault 100

    The highest value.

  • steptype numberdefault 1

    The amount the value changes by in one step.

  • tickstype booleandefault false

    Discrete: show a stop indicator at every step (use a coarse step).

  • disabledtype booleandefault false

    Turns the slider off: it can't be moved or focused.

  • valueLabeltype booleandefault false

    Show the value above the thumb while it is dragged or keyboard-focused.

  • formatOptionstype NumberFormatOptions

    Formats the value for the value indicator, and for assistive tech unless valueText says it in words.

  • valueTexttype ((value: number, index: number) => string)

    The value in words for assistive technology, each thumb's aria-valuetext, where a number format can't say it (a time: (seconds) => '1 minute 23 seconds of 10 minutes'), given the thumb's index too (0, or 1 for a range's end). Without it the value is read as formatOptions formats it; the value indicator keeps that format.

  • nametype string

    Form field name (one hidden input per thumb).

  • idtype string

    The id of the slider's root, its group (an error summary can link to it).

  • reftype Ref<HTMLDivElement>

    Ref to the root <div> element.

  • valuetype [number, number]

    The range, as [start, end] (controlled).

  • defaultValuetype [number, number]default [min, max]

    The initial range when uncontrolled.

Events

  • onChangetype ((value: [number, number]) => void)

    Called as the range changes, while dragging too.

  • onChangeEndtype ((value: [number, number]) => void)

    Called when the user stops dragging or releases a key.

Text

  • aria-labeltype string

    Accessible name when there's no visible label.

    One of aria-label or aria-labelledby is required.

  • labelstype Partial<RangeSliderLabels>

    Words the range slider announces (its thumbs' names), with English defaults. A LabelsProvider sets them for the whole app.

  • aria-labelledbytype string

    The id of the visible label that names the slider.

    One of aria-label or aria-labelledby is required.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Tokens

M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.

Slider tokens (md-comp-slider)
VariableDefaultPaintsCompose
--md-comp-slider-active-track-colorvar(--md-sys-color-primary)The track between the start (or the other thumb) and the handle.SliderTokens.ActiveTrackColor
--md-comp-slider-inactive-track-colorvar(--md-sys-color-secondary-container)The rest of the track.SliderTokens.InactiveTrackColor
--md-comp-slider-handle-colorvar(--md-sys-color-primary)The handle.SliderTokens.HandleColor
--md-comp-slider-stop-indicator-colorvar(--md-sys-color-on-secondary-container)The stop indicators and tick marks on the inactive track.SliderTokens.StopIndicatorColor
--md-comp-slider-value-indicator-container-colorvar(--md-sys-color-inverse-surface)The value indicator’s container.SliderTokens.ValueIndicatorContainerColor
--md-comp-slider-value-indicator-label-label-text-colorvar(--md-sys-color-inverse-on-surface)The value indicator’s text.SliderTokens.ValueIndicatorLabelTextColor

Spec status

Built to the M3 Expressive slider spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.

  • Standard

    Built

    Variant · Sizes

  • Centered

    Built

    Variant · Discrete

  • Range

    Built

    Variant · Range

  • Discrete

    Built

    Variant · Discrete

  • Orientation: horizontal and vertical

    Built

    Configuration · Sizes, Vertical

  • Size: XS to XL

    Built

    Configuration · Sizes

  • Inset icon

    Built

    Configuration · Value label

  • Stops

    Built

    Configuration · Discrete

  • Value indicator

    Built

    Configuration · Value label

  • Haptics

    Differs

    There are no haptics. A press on a discrete track maps through the corner inset its stops are drawn with, so a tap on a drawn stop selects that stop.

  • trailingIcon

    Extension

    A second inset icon at the inactive track's end (from Material Components Android); the spec shows one inset icon.

  • formatOptions

    Extension

    Formats the value indicator and what assistive tech announces, e.g. as a percentage.

Bundle size

Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.

  • Slider, RangeSlider: 16.0 kB

M3 Expressive specs

Sizes
xs, sm, md, lg, xl

Differences from Compose

  • Compose ships one size (16px track, 44px handle); the Expressive sizes xs–xl follow the M3 spec's measurements — tracks 16 / 24 / 40 / 56 / 96px, handles 44 / 44 / 52 / 68 / 108px.
  • Active track and handle are primary, the inactive track secondary-container; the 4px handle narrows to 2px while pressed, dragged or keyboard-focused, with a gap each side.
  • The track geometry ports Compose's drawTrack as CSS length expressions, so the first server render is exact and resizing needs no measuring; range and centred tracks carry stop indicators at both ends.
  • Stop indicators and ticks use the M3 token table's colours, not Compose's code: on-primary on the active track and on-secondary-container on the inactive one (disabled, inverse-on-surface and on-surface at 38%).
  • Inset icons follow MDC — a leadingIcon 10px inside the active track's start and an trailingIcon 10px inside the inactive end (replacing the stop) on sizes md and up. When the active track is too short for the start icon, it moves to the start of the inactive track (M3). Centred sliders and XS / S sliders ignore inset icons (with a development warning), as M3 advises. The value indicator pill is not in Compose's default slider.
  • On touch screens it behaves like Compose's draggable slider: a swipe across the slider scrolls the page and leaves the value alone, a tap on the track sets the value when the finger lifts, and a drag along the track moves the nearest thumb once it passes 8px. Mouse presses set the value at once.
  • Deviation: there are no haptics. A press on a discrete track maps through the same corner inset its stops are drawn with, so a tap on a drawn stop selects that stop at every size.