> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/sdk-core-ui/components/slider.md). Agents can also search and read this documentation through its [MCP server](https://docs.rierino.com/~gitbook/mcp).

# Slider

Lets people pick a number, or a range of numbers, by dragging along a track.

{% code title="slider/demo.tsx" %}

```tsx
import { useState } from "react";
import { Slider } from "@rierino-open/core-ui";

export default function SliderDemo() {
  const [volume, setVolume] = useState(40);

  return (
    <div style={{ width: 320, display: "grid", gap: 6 }}>
      <span id="stock-alert" style={{ fontSize: 12, fontWeight: 600 }}>
        Low stock alert
      </span>
      <Slider aria-labelledby="stock-alert" value={volume} onChange={(v) => setVolume(v as number)} />
    </div>
  );
}
```

{% endcode %}

## Usage

{% tabs %}
{% tab title="React app" %}

```tsx
import { Slider } from '@rierino-open/core-ui';

<Slider
  aria-label="Low stock alert"
  value={threshold}
  onChange={(value) => setThreshold(value as number)}
/>
```

{% endtab %}

{% tab title="Hosted editor" %}

```jsx
import CoreUI from '@rierino-open/core-ui';
const { Slider } = CoreUI;

<Slider
  aria-label="Low stock alert"
  value={threshold}
  onChange={(value) => setThreshold(value)}
/>
```

{% endtab %}
{% endtabs %}

The value runs from 0 to 100 by default and is shown above the track. `onChange` is called continuously while dragging. Use `value` for a controlled slider, or `defaultValue` to let it manage its own state.

{% hint style="info" %}
**Label the slider yourself**

Slider doesn't render a label: its `label` and `description` props are ignored. Name it with `aria-label`, or put a visible label next to it and point `aria-labelledby` at it, as in the example above.
{% endhint %}

## Examples

### Range

Pass two numbers as the value to get two thumbs. The value and `onChange` then use an array, `[low, high]`, and the thumbs can't pass each other.

{% code title="slider/range.tsx" %}

```tsx
import { Slider } from "@rierino-open/core-ui";

export default function SliderRange() {
  return (
    <div style={{ width: 320 }}>
      <Slider
        aria-label="Price range"
        defaultValue={[20, 80]}
        maxValue={200}
        formatOptions={{ style: "currency", currency: "EUR", maximumFractionDigits: 0 }}
      />
    </div>
  );
}
```

{% endcode %}

`formatOptions` takes [`Intl.NumberFormat` options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options), so values can be shown as currencies, percentages or units in the user's locale.

### Bounds and steps

`minValue`, `maxValue` and `step` set the range and the increment. Pass a function to `showValue` to write the shown value yourself; it receives every thumb's value as an array.

{% code title="slider/steps.tsx" %}

```tsx
import { Slider } from "@rierino-open/core-ui";

export default function SliderSteps() {
  return (
    <div style={{ width: 320 }}>
      <Slider
        aria-label="Discount"
        minValue={0}
        maxValue={50}
        step={5}
        defaultValue={15}
        showValue={([value]) => `${value}% off`}
      />
    </div>
  );
}
```

{% endcode %}

### Saving when released

`onChangeEnd` is called once, when the thumb is released or a key press ends. Use it for work that shouldn't run on every move, such as saving or fetching. `showValue={false}` hides the value above the track.

{% code title="slider/on-change-end.tsx" %}

```tsx
import { useState } from "react";
import { Slider } from "@rierino-open/core-ui";

export default function SliderOnChangeEnd() {
  const [live, setLive] = useState(30);
  const [saved, setSaved] = useState(30);

  return (
    <div style={{ width: 320, display: "grid", gap: 8, fontSize: 12 }}>
      <Slider
        aria-label="Commission"
        value={live}
        onChange={(v) => setLive(v as number)}
        onChangeEnd={(v) => setSaved(v as number)}
        showValue={false}
      />
      <span>While dragging: {live}</span>
      <span>Saved on release: {saved}</span>
    </div>
  );
}
```

{% endcode %}

### Sizes

`size="small"` draws a thinner track with smaller thumbs.

{% code title="slider/sizes.tsx" %}

```tsx
import { Slider } from "@rierino-open/core-ui";

export default function SliderSizes() {
  return (
    <div style={{ width: 320, display: "grid", gap: 20 }}>
      <Slider aria-label="Base size" defaultValue={60} />
      <Slider aria-label="Small size" size="small" defaultValue={60} />
    </div>
  );
}
```

{% endcode %}

### Vertical

`orientation="vertical"` stands the slider up, 224px tall, filling from the bottom.

{% code title="slider/vertical.tsx" %}

```tsx
import { Slider } from "@rierino-open/core-ui";

export default function SliderVertical() {
  return (
    <div style={{ display: "flex", gap: 40 }}>
      <Slider aria-label="Bass" orientation="vertical" defaultValue={70} />
      <Slider aria-label="Treble" orientation="vertical" defaultValue={40} />
    </div>
  );
}
```

{% endcode %}

### Disabled

{% code title="slider/disabled.tsx" %}

```tsx
import { Slider } from "@rierino-open/core-ui";

export default function SliderDisabled() {
  return (
    <div style={{ width: 320 }}>
      <Slider aria-label="Locked rate" defaultValue={25} isDisabled />
    </div>
  );
}
```

{% endcode %}

A disabled slider is dimmed, can't be focused, and ignores clicks and drags.

## Keyboard

| Key              | Action                                            |
| ---------------- | ------------------------------------------------- |
| `←` `→`, `↓` `↑` | Moves the focused thumb by one `step`             |
| `Home` `End`     | Moves the focused thumb to the minimum or maximum |
| `Tab`            | Moves between the thumbs of a range               |

Clicking the track moves the nearest thumb to that point.

## Accessibility

* Each thumb is a native range input, so screen readers announce its value as it changes, using `formatOptions`.
* **Name the slider** with `aria-label` or `aria-labelledby`. For a range, each thumb is announced with the slider's name and its own value.

## Styling

The filled part of the track uses `--primary`, and the rest of the track uses `--primary` at 50%. See [theme variables](https://docs.rierino.com/sdk-core-ui/foundations/colors.md#theme-variables).

| Target           | How                          |
| ---------------- | ---------------------------- |
| The whole slider | `className`                  |
| The track        | The `Rie-track` class        |
| The thumbs       | The `Rie-slider-thumb` class |

| Attribute            | On             | Present when                 |
| -------------------- | -------------- | ---------------------------- |
| `data-orientation`   | Slider         | `horizontal` or `vertical`   |
| `data-disabled`      | Slider, thumbs | `isDisabled` is set          |
| `data-focus-visible` | Thumb          | The thumb has keyboard focus |
| `data-dragging`      | Thumb          | The thumb is being dragged   |

### Building your own layout

The parts are exported for custom layouts: `Slider.Root`, `Slider.Track`, `Slider.Filler`, `Slider.Thumb` (with an `index` for each thumb), `Slider.Output` for the value, and `Slider.Controls`, which renders the track, filler and thumbs together.

## API reference

| Prop              | Type                                       | Default        | Description                                                                                                                                                                        |
| ----------------- | ------------------------------------------ | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `aria-label`      | `string`                                   |                | Defines a string value that labels the current element.                                                                                                                            |
| `aria-labelledby` | `string`                                   |                | Identifies the element (or elements) that labels the current element.                                                                                                              |
| `value`           | `number \| number[]`                       |                | The current value (controlled).                                                                                                                                                    |
| `defaultValue`    | `number \| number[]`                       |                | The default value (uncontrolled).                                                                                                                                                  |
| `onChange`        | `((value: number \| number[]) => void)`    |                | Handler that is called when the value changes.                                                                                                                                     |
| `orientation`     | `Orientation`                              | `'horizontal'` | The orientation of the Slider.                                                                                                                                                     |
| `isDisabled`      | `boolean`                                  |                | Whether the whole Slider is disabled.                                                                                                                                              |
| `onChangeEnd`     | `((value: number \| number[]) => void)`    |                | Fired when the slider stops moving, due to being let go.                                                                                                                           |
| `minValue`        | `number`                                   | `0`            | The slider's minimum value.                                                                                                                                                        |
| `maxValue`        | `number`                                   | `100`          | The slider's maximum value.                                                                                                                                                        |
| `step`            | `number`                                   | `1`            | The slider's step value.                                                                                                                                                           |
| `className`       | `string \| ((state) => string)`            |                | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
| `formatOptions`   | `Intl.NumberFormatOptions`                 |                | The display format of the value label.                                                                                                                                             |
| `size`            | `"base" \| "small"`                        | `"base"`       | `small` draws a thinner track and smaller thumbs.                                                                                                                                  |
| `showValue`       | `boolean \| ((value: number[]) => string)` | `true`         | Shows the current value above the track. Pass a function to format it yourself; it receives every thumb's value as an array.                                                       |

Slider also accepts the other props of React Aria's [Slider](https://react-spectrum.adobe.com/react-aria/Slider.html#props).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/sdk-core-ui/components/slider.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
