React

Slider

A component that allows selecting and inputting one or two values within a specified range.

Available since@seed-design/react@1.1.0, @seed-design/css@1.1.0

Installation

npx @seed-design/cli@latest add ui:slider

Props

Prop

Type

label?React.ReactNode
indicator?React.ReactNode
description?React.ReactNode
errorMessage?React.ReactNode
showRequiredIndicator?boolean | undefined
fieldRef?React.Ref<HTMLDivElement> | undefined
name?string | undefined
getAriaValuetext?((value: number) => string) | undefined
getAriaLabel?((thumbIndex: number) => string) | undefined
getAriaLabelledby?((thumbIndex: number) => string) | undefined
minnumber
maxnumber
values?number[] | undefined
onValuesChange?((value: number[]) => void) | undefined
onValuesCommit?((value: number[]) => void) | undefined

Examples

Basic

Set the value range of the slider by setting min and max.

Steps

You can configure so values can only be selected at specific intervals.

Allowed Values

You can limit the values that can be selected on the slider using the allowedValues prop. When allowedValues is specified, step and minStepsBetweenThumbs are ignored.

With Ticks

You can display tick marks on the slider track.

Thin

Mainly used when the step is small enough to feel continuous.

Thick

Mainly used when the step is large enough to feel discrete or when the thumb can only be positioned on ticks.

With Markers

You can display markers below the slider.

Caution

Screen readers do not read markers. If you need to inform the user when a specific value is selected, use the getAriaValuetext prop to also provide text describing the currently selected value.

Controlled

Control the slider's state externally using the values and onValuesChange props.

Listening to Value Changes

  • onValuesChange
    • Called whenever the slider's value changes. Use this prop to track the slider's value in real time.
  • onValuesCommit
    • Called when the slider's value change is complete. Useful for finalizing the value when the user finishes manipulating the slider and releases.

Disabled

Hide Range

Use the hideRange prop to hide the default range color and apply custom styles.

Customizing Value Indicator

Value Indicator Label

Use the getValueIndicatorLabel prop to customize the content of the tooltip displayed above the thumb.

Caution

The Value Indicator is displayed only while the thumb is pressed, and screen readers do not read the content of the Value Indicator. If the Value Indicator contains meaningful content, it is recommended to also use the getAriaValuetext prop.

Value Indicator Trigger

You can set the condition under which the value indicator is displayed with the valueIndicatorTrigger prop. The default value is "auto", where the Value Indicator display condition varies based on the device environment.

  • Mouse environment: The Value Indicator is displayed on thumb hover. Setting valueIndicatorTrigger="hover" always behaves this way.
  • Touch environment: The Value Indicator is displayed on thumb active. Setting valueIndicatorTrigger="active" always behaves this way.

When focusing the thumb via keyboard, the Value Indicator is always displayed regardless of the valueIndicatorTrigger value.

Hide Value Indicator

Use the hideValueIndicator prop to hide the Value Indicator tooltip displayed above the thumb.

Range Slider

You can select a range using two thumbs.

Minimum Steps Between Thumbs

You can set the minimum spacing between two thumbs.

Accessibility

getAriaValuetext

By default, screen readers read the numeric value that each thumb points to. If the numeric value alone cannot sufficiently convey information, use the getAriaValuetext prop to provide a human-friendly description. You can add units or include text describing the meaning of the value.

getAriaLabel and getAriaLabelledby

Use the getAriaLabel or getAriaLabelledby prop to provide a description for each thumb. This helps screen reader users understand the purpose of each thumb.

Especially for range-selection sliders, you should describe the role each thumb plays in the range. (minimum-maximum, start-end, etc.)

Field Integration

You can use Field-related props such as label, description, and errorMessage.

Use Cases

Form (Uncontrolled)

React Hook Form

RTL Support

Table of contents