The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
---
title: Slider
description: Choose a numeric value or range with draggable, keyboard-accessible thumbs.
---
import { PageBanner } from "/snippets/page-banner.mdx"
import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';
import SliderReference from '/snippets/ui/generated/input/slider.mdx';
## Overview
`Slider` supports a single number or an array of numbers for a range. Compose its label, track, indicator, and thumbs inside `Root`.
<StoryEmbed
storyId="ui-input-slider--display"
title="Slider example"
height={120}
/>
## Usage
### Uncontrolled state
Use `defaultValue` to set the initial volume. The slider owns subsequent changes.
```tsx
import { Slider } from 'twenty-ui/primitives/input';
import { Text } from 'twenty-ui/primitives/typography';
export const VolumeSlider = () => (
<Slider.Root name="volume" defaultValue={40} min={0} max={100} step={1}>
<Text
render={<div />}
style={{ display: 'flex', justifyContent: 'space-between' }}
>
<Slider.Label>Volume</Slider.Label>
<Slider.Value />
</Text>
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
<Slider.Thumb />
</Slider.Track>
</Slider.Control>
</Slider.Root>
);
```
## Visual choices
Compare the accent and success colors at minimum, middle, maximum, and disabled values. The enabled sliders remain interactive.
<StoryEmbed
storyId="ui-input-slider--catalog"
title="Visual choices for slider"
height={340}
/>
## Anatomy
Put the track and thumbs inside `Slider.Control`, which handles pointer interaction. This tree shows a single-thumb slider.
```text
Slider.Root
├── Slider.Label
├── Slider.Value
└── Slider.Control
└── Slider.Track
├── Slider.Indicator
└── Slider.Thumb
```
| Part | Requirement | Purpose |
| ----------- | ----------------------------- | --------------------------------------------------------------- |
| `Root` | Required | Owns the value, bounds, step, and orientation. |
| `Control` | Required | Handles pointer interaction and positions the thumbs. |
| `Track` | Required for the styled track | Shows the full value range. |
| `Thumb` | One per adjustable value | Provides a focusable handle with keyboard interaction. |
| `Label` | Recommended | Supplies a visible label; every thumb needs an accessible name. |
| `Value` | Optional | Displays the current numeric value. |
| `Indicator` | Optional | Shows the selected portion of the track. |
For a range, add a thumb for each value with its matching `index` and a distinct accessible name. Labels and numeric output stay outside `Control`, so they do not become part of the draggable area.
## Controlled state
Pass `value` and update it with `onValueChange` to own the same volume in React state. The callback receives the next value and event details.
```tsx
import { useState } from 'react';
import { Slider } from 'twenty-ui/primitives/input';
export const VolumeSlider = () => {
const [volume, setVolume] = useState(40);
return (
<Slider.Root
name="volume"
value={volume}
onValueChange={setVolume}
min={0}
max={100}
step={1}
>
<Slider.Label>Volume</Slider.Label>
<Slider.Value />
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
<Slider.Thumb />
</Slider.Track>
</Slider.Control>
</Slider.Root>
);
};
```
Use `onValueChange` to keep the controlled value current during an interaction. `onValueCommitted` handles the final value when the interaction finishes, for example to save it. Both callbacks are also available in uncontrolled mode without taking ownership of the value.
Change details include the originating `event`, the interaction `reason`, the `activeThumbIndex`, and `cancel()`. Commit details use Base UI's generic event contract and do not include change cancellation. A canceled change does not commit.
## Range
```tsx
import { Slider } from 'twenty-ui/primitives/input';
export const PriceRange = () => (
<Slider.Root
defaultValue={[25, 75]}
min={0}
max={100}
minStepsBetweenValues={10}
>
<Slider.Label>Price range</Slider.Label>
<Slider.Value />
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
<Slider.Thumb index={0} aria-label="Minimum price" />
<Slider.Thumb index={1} aria-label="Maximum price" />
</Slider.Track>
</Slider.Control>
</Slider.Root>
);
```
Give range thumbs distinct accessible names and an `index` corresponding to their value. `minStepsBetweenValues` sets the minimum gap in steps. The root's generic value type is a number or a readonly array of numbers.
To control a range, store the array in React state and pass it through `value` and `onValueChange`, just as for a single value.
## Keyboard and appearance
Arrow keys adjust a focused thumb by a step. Home and End move it toward the bounds while respecting range constraints. `orientation="vertical"` changes the layout and keyboard direction. Use `disabled` on `Root` to prevent changes.
Set `color="success"` for the alternative palette; the default is `accent`.
The default `thumbAlignment` is `edge`. Pass `center` or `edge-client-only` to override it. Native `className`, `style`, and `render` composition remain available on each part, including state functions.
<Note>
With `edge` and `edge-client-only` alignment, Base UI 1.8 and 1.9 never
re-measure a thumb after its `Slider.Control` resizes, and a slider mounted
while hidden keeps its thumbs hidden once shown
([mui/base-ui#5995](https://github.com/mui/base-ui/issues/5995)). React front
components hit the same issue on their first render. Use
`thumbAlignment="center"` until a Base UI release includes the fix
([mui/base-ui#6000](https://github.com/mui/base-ui/pull/6000)).
</Note>
## Native integration and types
`Slider.Root` infers a number or a readonly numeric array from `value` or `defaultValue`, retaining that type in both callbacks. `SliderRootProps` accepts both by default; use `SliderRootProps<number>` for single-value helpers or `SliderRootProps<readonly number[]>` for range helpers.
Every part has an exported props type in `twenty-ui/primitives/input`: `SliderRootProps`, `SliderControlProps`, `SliderTrackProps`, `SliderIndicatorProps`, `SliderThumbProps`, `SliderLabelProps`, and `SliderValueProps`.
Refs target div elements for Root, Control, Track, Indicator, Thumb, and Label, and an output element for Value. A Thumb's ref targets its visible handle; its accessible name and native form value belong to the nested range input. Use `name` and `form` on Root for native submission, with one input per range value.
## Props
The reference is generated from the public component types. Native attributes, including accessible names and event handlers, are also accepted on parts that render elements.
<SliderReference />
<PageBanner illustration="section-apps-config" />