GitHub

Slider

Range slider input

Basic Usage

Loading...

Installation

pnpm add @corew500/ui

Usage

import { Slider } from "@corew500/ui/slider"

<Slider>Content</Slider>

Variants

sliderControlVariants

AxisValuesDefault
size
smdefaultlg
default

sliderTrackVariants

AxisValuesDefault
size
smdefaultlg
default

sliderThumbVariants

AxisValuesDefault
size
smdefaultlg
default

CMS Integration

CMSPayload CMS Integration
This component supports CMS-driven content via @corew500/cms-payload.
Loading...

API Reference

Props

PropTypeDefaultDescription
classNameenumCSS class applied to the element, or a function that returns a class based on the component’s state.
defaultValueenumThe uncontrolled value of the slider when it’s initially rendered. To render a controlled slider, use the `value` prop instead.
styleenumStyle applied to the element, or a function that returns a style object based on the component’s state.
disabledenumfalseWhether the slider should ignore user interaction.
formatNumberFormatOptionsOptions to format the input value.
localeenumThe locale used by `Intl.NumberFormat` when formatting the value. Defaults to the user's runtime locale.
maxnumber100The maximum allowed value of the slider. Should not be equal to min.
minnumber0The minimum allowed value of the slider. Should not be equal to max.
minStepsBetweenValuesnumber0The minimum steps between values in a range slider.
namestringIdentifies the field when a form is submitted.
orientationenum'horizontal'The component orientation.
stepnumber1The granularity with which the slider can step through values. (A "discrete" slider.) The `min` prop serves as the origin for the valid values. We recommend (max - min) to be evenly divisible by the step.
largeStepnumber10The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down.
thumbAlignmentenum'center'How the thumb(s) are aligned relative to `Slider.Control` when the value is at `min` or `max`: - `center`: The center of the thumb is aligned with the control edge - `edge`: The thumb is inset within the control such that its edge is aligned with the control edge - `edge-client-only`: Same as `edge` but renders after React hydration on the client, reducing bundle size in return
thumbCollisionBehaviorenum'push'Controls how thumbs behave when they collide during pointer interactions. - `'push'` (default): Thumbs push each other without restoring their previous positions when dragged back. - `'swap'`: Thumbs swap places when dragged past each other. - `'none'`: Thumbs cannot move past each other; excess movement is ignored.
valueenumThe value of the slider. For ranged sliders, provide an array with two values.
onValueChange(value: number | readonly number[], eventDetails: SliderRootChangeEventDetails) => voidCallback function that is fired when the slider's value changed. You can pull out the new value by accessing `event.target.value` (any). The `eventDetails.reason` indicates what triggered the change: - `'input-change'` when the hidden range input emits a change event (for example, via form integration) - `'track-press'` when the control track is pressed - `'drag'` while dragging a thumb - `'keyboard'` for keyboard input - `'none'` when the change is triggered without a specific interaction
onValueCommitted(value: number | readonly number[], eventDetails: SliderRootCommitEventDetails) => voidCallback function that is fired when the `pointerup` is triggered. **Warning**: This is a generic event not a change event. The `eventDetails.reason` indicates what triggered the commit: - `'drag'` while dragging a thumb - `'track-press'` when the control track is pressed - `'keyboard'` for keyboard input - `'input-change'` when the hidden range input emits a change event (for example, via form integration) - `'none'` when the commit occurs without a specific interaction
renderenumAllows you to replace the component’s HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
sizeenum

Accessibility

Keyboard Navigation

  • Keyboard accessible: Arrow keys to adjust value, Home/End for min/max
  • Focus visible ring on thumb for keyboard navigation
  • For range sliders, Tab moves between thumbs

Screen Readers

  • - Uses `role="slider"` for proper semantics (handled by Base UI)
  • `aria-valuemin`, `aria-valuemax`, `aria-valuenow` managed automatically

Additional

  • Disabled state indicated visually via reduced opacity

Localization

Translatable Content

  • - Labels should be provided externally via `FieldLabel`
  • For accessible name, use `aria-label` or associate with a label

Locale-Specific Formatting

  • Value formatting (if displayed) should be handled externally

Related

Related Components