Slider
A slider component that selects one or two values from a specified range.
Installation
Install dependencies
Copy the code below and paste it in
Props
Slider
The Slider in Registry is a convenience wrapper that combines the Slider primitive with Field guidance elements. When using one thumb, put one value in defaultValues or values, and when selecting a range, put two values.
Prop
Type
label?React.ReactNodeindicator?React.ReactNodedescription?React.ReactNodeerrorMessage?React.ReactNodeshowRequiredIndicator?boolean | undefinedrequired?boolean | undefinedfieldRef?React.Ref<NodesRef> | undefinedclassName?string | undefinedstyle?CSSProperties | undefinedmain-thread:bindbgload?EventHandler<BaseImageLoadEvent<Element>> | undefinedmain-thread:catchbgload?EventHandler<BaseImageLoadEvent<Element>> | undefinedmain-thread:capture-bindbgload?EventHandler<BaseImageLoadEvent<Element>> | undefinedmain-thread:capture-catchbgload?EventHandler<BaseImageLoadEvent<Element>> | undefinedmain-thread:global-bindbgload?EventHandler<BaseImageLoadEvent<Element>> | undefinedmain-thread:bindbgerror?EventHandler<BaseImageErrorEvent<Element>> | undefinedmain-thread:catchbgerror?EventHandler<BaseImageErrorEvent<Element>> | undefinedmain-thread:capture-bindbgerror?EventHandler<BaseImageErrorEvent<Element>> | undefinedmain-thread:capture-catchbgerror?EventHandler<BaseImageErrorEvent<Element>> | undefinedmain-thread:global-bindbgerror?EventHandler<BaseImageErrorEvent<Element>> | undefinedmain-thread:bindtouchstart?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchtouchstart?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindtouchstart?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchtouchstart?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindtouchstart?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindtouchmove?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchtouchmove?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindtouchmove?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchtouchmove?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindtouchmove?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindtouchcancel?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchtouchcancel?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindtouchcancel?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchtouchcancel?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindtouchcancel?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindtouchend?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchtouchend?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindtouchend?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchtouchend?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindtouchend?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindlongpress?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchlongpress?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindlongpress?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchlongpress?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindlongpress?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindtransitionstart?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:catchtransitionstart?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-bindtransitionstart?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-catchtransitionstart?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:global-bindtransitionstart?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:bindtransitioncancel?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:catchtransitioncancel?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-bindtransitioncancel?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-catchtransitioncancel?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:global-bindtransitioncancel?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:bindtransitionend?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:catchtransitionend?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-bindtransitionend?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-catchtransitionend?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:global-bindtransitionend?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:bindanimationstart?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:catchanimationstart?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-bindanimationstart?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-catchanimationstart?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:global-bindanimationstart?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:bindanimationiteration?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:catchanimationiteration?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-bindanimationiteration?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-catchanimationiteration?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:global-bindanimationiteration?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:bindanimationcancel?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:catchanimationcancel?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-bindanimationcancel?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-catchanimationcancel?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:global-bindanimationcancel?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:bindanimationend?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:catchanimationend?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-bindanimationend?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-catchanimationend?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:global-bindanimationend?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:bindmousedown?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmousedown?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmousedown?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmousedown?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmousedown?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmouseup?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmouseup?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmouseup?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmouseup?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmouseup?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmousemove?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmousemove?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmousemove?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmousemove?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmousemove?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmouseenter?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmouseenter?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmouseenter?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmouseenter?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmouseenter?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmouseleave?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmouseleave?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmouseleave?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmouseleave?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmouseleave?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmouseclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmouseclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmouseclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmouseclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmouseclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmousedblclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmousedblclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmousedblclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmousedblclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmousedblclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmouselongpress?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmouselongpress?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmouselongpress?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmouselongpress?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmouselongpress?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindwheel?EventHandler<BaseWheelEvent<Element>> | undefinedmain-thread:catchwheel?EventHandler<BaseWheelEvent<Element>> | undefinedmain-thread:capture-bindwheel?EventHandler<BaseWheelEvent<Element>> | undefinedmain-thread:capture-catchwheel?EventHandler<BaseWheelEvent<Element>> | undefinedmain-thread:global-bindwheel?EventHandler<BaseWheelEvent<Element>> | undefinedmain-thread:bindzoom?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchzoom?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindzoom?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchzoom?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindzoom?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindkeydown?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:catchkeydown?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:capture-bindkeydown?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:capture-catchkeydown?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:global-bindkeydown?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:bindkeyup?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:catchkeyup?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:capture-bindkeyup?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:capture-catchkeyup?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:global-bindkeyup?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:bindfocus?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:catchfocus?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:capture-bindfocus?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:capture-catchfocus?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:global-bindfocus?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:bindblur?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:catchblur?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:capture-bindblur?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:capture-catchblur?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:global-bindblur?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:bindlayoutchange?EventHandler<LayoutChangeDetailEvent<Element>> | undefinedmain-thread:catchlayoutchange?EventHandler<LayoutChangeDetailEvent<Element>> | undefinedmain-thread:capture-bindlayoutchange?EventHandler<LayoutChangeDetailEvent<Element>> | undefinedmain-thread:capture-catchlayoutchange?EventHandler<LayoutChangeDetailEvent<Element>> | undefinedmain-thread:global-bindlayoutchange?EventHandler<LayoutChangeDetailEvent<Element>> | undefinedmain-thread:binduiappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:catchuiappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:capture-binduiappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:capture-catchuiappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:global-binduiappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:binduidisappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:catchuidisappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:capture-binduidisappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:capture-catchuidisappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:global-binduidisappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:bindaccessibilityaction?EventHandler<AccessibilityActionDetailEvent<Element>> | undefinedmain-thread:catchaccessibilityaction?EventHandler<AccessibilityActionDetailEvent<Element>> | undefinedmain-thread:capture-bindaccessibilityaction?EventHandler<AccessibilityActionDetailEvent<Element>> | undefinedmain-thread:capture-catchaccessibilityaction?EventHandler<AccessibilityActionDetailEvent<Element>> | undefinedmain-thread:global-bindaccessibilityaction?EventHandler<AccessibilityActionDetailEvent<Element>> | undefinedmain-thread:bindtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindlongtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchlongtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindlongtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchlongtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindlongtap?EventHandler<BaseTouchEvent<Element>> | undefinedvalues?number[] | undefineddefaultValues?number[] | undefinedmin?number | undefinedmax?number | undefinedstep?number | undefinedallowedValues?number[] | undefinedminStepsBetweenThumbs?number | undefineddir?"ltr" | "rtl" | undefineddisabled?boolean | undefinedreadOnly?boolean | undefinedinvalid?boolean | undefinedonValuesChange?((values: number[]) => void) | undefinedonValuesCommit?((values: number[]) => void) | undefinedgetAccessibilityLabel?((thumbIndex: number) => string) | undefinedgetAccessibilityValueText?((value: number, thumbIndex: number) => string) | undefinedgetValueIndicatorLabel?((params: { value: number; thumbIndex: number; }) => React.ReactNode) | undefinedvalueIndicatorTrigger?"auto" | "active" | undefinedThe Registry wrapper provides two types of props:
- Slider state and behavior: Directly passes
values,defaultValues,min,max,step,allowedValues,minStepsBetweenThumbs,dir,disabled,readOnly,invalid,onValuesChange,onValuesCommit,getAccessibilityLabel,getAccessibilityValueText,getValueIndicatorLabel, andvalueIndicatorTriggerfrom thelow-level Root. - Display and Field guidance: Provides
label,labelWeight,indicator,description,errorMessage,showRequiredIndicator,markers,ticks,tickWeight,hideRange,hideValueIndicator, andfieldRef. Each item inmarkersis a number or a{ value, label?, align? }object.
When allowedValues is specified, only allowed values can be selected and it takes precedence over step and minStepsBetweenThumbs. When values and onValuesChange are used together, it becomes a controlled state, and onValuesCommit is called when the value is finalized.
Usage
Instead of using the Registry composition, you can directly use the @seed-design/lynx-react primitives. Combine SliderControl and SliderTrack inside SliderRoot, and place SliderRange and necessary SliderTick inside the track. Create each thumb with SliderThumb, and the Value Indicator is composed of SliderValueIndicatorRoot, SliderValueIndicatorArrow, and SliderValueIndicatorArrowTip and SliderValueIndicatorLabel within it. If you need markers, place SliderMarker inside SliderMarkers.
The index of SliderThumb indicates the position of the thumb in the values array. When directly combining package primitives, value changes and submission and validation are still handled in app state and request flow.
Examples
Basic
Set the selection range with min and max, and select a value with one thumb.
Steps
Set the selection interval with step to select only values in fixed increments.
Allowed Values
Specify selectable values with allowedValues. When this prop is set, allowedValues takes precedence over step and minStepsBetweenThumbs.
With Ticks
You can display ticks on the track that indicate the selection unit.
Thin
Use small intervals and display thin ticks to make it appear as continuous manipulation.
Thick
Display thick ticks when the value intervals are large or selection is only allowed at tick positions.
With Markers
Display markers below the slider that explain key values. Marker visual text is not automatically included in native accessibility values, so pass necessary meaning through getAccessibilityValueText.
You can pass a number or a { value, label?, align? } object to markers. If align is omitted in the object, the minimum value is placed at the start, the maximum value at the end, and others in the center.
Controlled
Control the slider value with app state using values and onValuesChange.
Listening to Value Changes
onValuesChange: Called whenever the value changes during dragging. Use this to display the current value on screen or update app state in real time.onValuesCommit: Called when value changes are complete. In Lynx native, it is called once on touch release of a drag with value changes. You do not need to add debounce to this callback.
Disabled
Use disabled to prevent thumb manipulation and display disabled state styling.
Hide Range
Use hideRange to hide the active range color and display only the track.
Customizing Value Indicator
Value Indicator Label
Change the text of the Value Indicator displayed when manipulating the thumb with getValueIndicatorLabel.
The Value Indicator is supplementary UI displayed during native touch manipulation and is not the value read by accessibility navigation. If you need to provide meaningful units or descriptions, also use getAccessibilityValueText.
Value Indicator Trigger
Set the conditions for displaying the Value Indicator with valueIndicatorTrigger. In Lynx, you can use "auto" and "active".
"active": Display on the thumb being manipulated with the current touch."auto"(default): Behaves identically to"active"in native touch environments.
Web's hover-based display conditions or keyboard focus-based behavior are not supported in Lynx native.
Hide Value Indicator
Hide the Value Indicator above the thumb with hideValueIndicator.
Range Slider
Select a range between two thumbs by passing two values to defaultValues or values.
Minimum Steps Between Thumbs
Specify the minimum distance to maintain between two thumbs with minStepsBetweenThumbs.
Accessibility
getAccessibilityValueText
Native accessibility navigation provides each thumb with a value in the format minimum <min>, maximum <max>, current <value> by default. If the number alone is not meaningful, use getAccessibilityValueText to provide a description including units or meaning of the value.
getAccessibilityLabel
Describe the purpose of each thumb with getAccessibilityLabel. Particularly in range sliders, provide a label that distinguishes whether each thumb represents the minimum or maximum value.
Field Integration
Use label, labelWeight, indicator, description, errorMessage, and showRequiredIndicator to display Field guidance around the slider. When invalid is true and there is an errorMessage, error guidance is displayed.
RTL Support
Create a slider with values arranged from right to left with dir="rtl".
Differences from Web Version
Lynx Slider has the following differences from React Slider:
- Rendering elements: Uses native
<view>and<text>instead of HTML form input and DOM elements. - Input events: Uses native touch input instead of browser pointer/keyboard events, with value changes passed via
onValuesChangeand finalization viaonValuesCommit. - Value Indicator:
valueIndicatorTrigger="auto"is equivalent to touch-active in native and is not displayed on hover. It provides the same result as"active". - Accessibility: Provides native accessibility name and value through
getAccessibilityLabelandgetAccessibilityValueTextinstead of DOM ARIA. - Field guidance: Registry's
label,description, anderrorMessageare displayed with native layout. Label and description connection via DOM id is not used. - Range selection: Represents range with
valuesarray and two native thumbs.
Lynx Unsupported Features
Since Lynx does not have HTML form and browser keyboard models, the following React-only features are not provided as working examples:
| Feature | Replacement or Limitation in Lynx |
|---|---|
form submission, React Hook Form | Manage app state with values and onValuesChange, and handle submission in the app's request flow. |
HiddenInput | There is no HTML hidden input. Construct the value to submit directly from app state. |
name | There is no native form field name. Use app state keys or request payload. |
| Browser validation and form field connection | Display screen errors with invalid and errorMessage, and perform validation in the app. |
getAriaLabelledby and DOM ARIA | There is no DOM id connection. Provide native accessibility through getAccessibilityLabel and getAccessibilityValueText. |
| Keyboard, focus, focus-visible | There is no keyboard thumb focus model. Use native touch and accessibility navigation. |
| Hover | There is no hover interaction in native. valueIndicatorTrigger="auto" behaves as touch-active like "active". |
Therefore, Form (Uncontrolled) and React Hook Form are excluded from working examples in Lynx documentation. Even when submission and validation are needed, connect slider values to app state and use the app's submission and validation logic along with native accessibility guidance.