# Slider: Controlled

> `onValueChange` fires on every move and `onValueCommitted` once on release, which is the moment to save. Setting the value from outside glides too.

Example: https://hextaui.com/docs/slider/examples/controlled
Component docs: https://hextaui.com/docs/slider.md

## Add this example

```bash
npx shadcn@latest add https://hextaui.com/r/slider-controlled.json
```

This adds `components/examples/slider/controlled.tsx` with the Slider component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/slider/controlled.tsx"
"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import { Slider, SliderLabel, SliderValue } from "@/components/ui/slider"

export function SliderControlled() {
  const [value, setValue] = React.useState(40)
  const [saved, setSaved] = React.useState(40)

  return (
    <div className="flex w-full max-w-xs flex-col gap-4">
      <Slider
        value={value}
        onValueChange={setValue}
        onValueCommitted={setSaved}
      >
        <SliderLabel>Brightness</SliderLabel>
        <SliderValue />
      </Slider>
      <div className="flex items-center justify-between gap-3">
        <span className="text-sm text-muted-foreground">Saved: {saved}</span>
        <div className="flex gap-2">
          <Button variant="outline" size="sm" onClick={() => setValue(0)}>
            Off
          </Button>
          <Button variant="outline" size="sm" onClick={() => setValue(100)}>
            Max
          </Button>
        </div>
      </div>
    </div>
  )
}
```

## Props in this example

### Slider

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number \| number[]` | – | The controlled value. One thumb per item. |
| `onValueChange` | `(value, eventDetails) => void` | – | Fires on every change while dragging. |
| `onValueCommitted` | `(value, eventDetails) => void` | – | Fires once when a change ends. |

## More Slider examples

- [Sizes](https://hextaui.com/docs/slider/examples/sizes.md)
- [Range](https://hextaui.com/docs/slider/examples/range.md)
- [Value bubble](https://hextaui.com/docs/slider/examples/value-bubble.md)
- [Steps and format](https://hextaui.com/docs/slider/examples/steps.md)
- [Vertical](https://hextaui.com/docs/slider/examples/vertical.md)
- [With icons](https://hextaui.com/docs/slider/examples/icons.md)
- [Disabled](https://hextaui.com/docs/slider/examples/disabled.md)
- [Long labels](https://hextaui.com/docs/slider/examples/long-label.md)
- [Right to left](https://hextaui.com/docs/slider/examples/rtl.md)
