PeakUI

Slider

Selects one or more values within a range

Usage

import {Slider} from "@peakui/react";

Anatomy

<Slider>
  <Label />
  <Slider.Output />
  <Slider.Track>
    <Slider.Fill />
    <Slider.Thumb />
  </Slider.Track>
</Slider>

Examples

Disabled

Range

Pass an array to defaultValue and render one Slider.Thumb per value through the track's render function.

Vertical

Controlled

Control the value with value and onChange.

Custom Value Formatting

Use formatOptions to format the displayed value.

Custom Output

Customize Slider.Output to control how the selected values are shown.

Render Function

Customization

Tailwind CSS

Global CSS

.slider {
  @apply grid w-full gap-1;
}

.slider__output {
  @apply text-muted text-sm;
}

Styling Reference

CSS Classes

ClassDescription
.sliderThe slider container element
.slider__outputThe output element displaying the current value(s)
.slider__trackThe track element containing the fill and thumbs
.slider__fillThe fill element showing the selected range
.slider__thumbThe thumb element
.slider__marksThe marks element

Slots

SlotDescription
[data-slot="slider"]The slider container element
[data-slot="slider-output"]The output element displaying the current value(s)
[data-slot="slider-track"]The track element containing the fill and thumbs
[data-slot="slider-fill"]The fill element showing the selected range
[data-slot="slider-thumb"]The thumb element
[data-slot="slider-marks"]The marks element

Interactive States

The component supports both CSS pseudo-classes and data attributes:

StateAttribute
Disabled[data-disabled="true"] / :disabled on the slider or thumb
Dragging[data-dragging="true"] on the thumb
Keyboard focused[data-focus-visible="true"] / :focus-visible on the thumb
Vertical[data-orientation="vertical"] on the slider
Fill starts at the beginning[data-fill-start="true"] on the track
Fill ends at the end[data-fill-end="true"] on the track

API Reference

Slider.Root

PropTypeDefaultDescription
valuenumber | number[]-Controlled value
defaultValuenumber | number[]-Uncontrolled initial value
onChange(value: number | number[]) => void-Called when the value changes
onChangeEnd(value: number | number[]) => void-Called when dragging ends
minValuenumber0Lower bound
maxValuenumber100Upper bound
stepnumber1Step size
formatOptionsIntl.NumberFormatOptions-Locale-aware formatting of the value label
orientation"horizontal" | "vertical""horizontal"Orientation of the slider
isDisabledboolean-Disables the slider
renderDOMRenderFunction<'div', SliderRenderProps>-Replaces the rendered element
...restEvery React Aria Slider attribute is accepted

Each thumb renders a visually hidden native <input type="range"> carrying the slider role, its value and its keyboard interaction.

Slider.Output

PropTypeDefaultDescription
childrenReactNode | RenderFunctionvalue labelsOverrides the joined value labels
renderDOMRenderFunction<'div', SliderOutputRenderProps>-Replaces the rendered element
...restEvery React Aria SliderOutput attribute is accepted

Slider.Track

PropTypeDefaultDescription
renderDOMRenderFunction<'div', SliderTrackRenderProps>-Replaces the rendered element
...restEvery React Aria SliderTrack attribute is accepted

Slider.Fill

PropTypeDefaultDescription
styleCSSProperties-Merged under the computed fill geometry
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'div'
...restEvery <div> attribute is accepted

Slider.Thumb

PropTypeDefaultDescription
indexnumber0Index of the thumb within the slider
isDisabledboolean-Disables this thumb
namestring-Name of the hidden input, used when submitting an HTML form
renderDOMRenderFunction<'div', SliderThumbRenderProps>-Replaces the rendered element
...restEvery React Aria SliderThumb attribute is accepted

Slider.Marks

PropTypeDefaultDescription
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'div'
...restEvery <div> attribute is accepted

Planned: Slider.Marks is a placeholder that renders an empty element — marks support is not implemented yet.

Render Props

children and className of Slider.Root, Slider.Output, Slider.Track and Slider.Thumb accept a function receiving the respective React Aria render props, including state with values and getThumbValueLabel.

On this page