# Slider

Picks a number, or a range, by dragging or with the arrow keys; Page Up and Page Down take big steps, Home and End go to the ends. Built on ui-sdk's Slider. Pair it with SliderValue or a field so the number can be read.

- Beta: ready to use; its API can still change in a minor release.
- Category: Selection

```tsx
import { Slider, SliderValue } from "@leap-crm/design-system";
```

## Best practices

- Do: Pair it with `SliderValue` or a field, so the number can be read, like a 60% probability on an opportunity.
- Do: Name it with `aria-label` or a `Label`. For a range, name each thumb with `thumbLabels`, like Minimum and Maximum.
- Do: Save in `onValueCommit`, which runs when the drag ends, rather than on every step of `onValueChange`.
- Don't: Use it for an exact figure, like a fee estimate or a matter number. Use `Input`: typing an exact value is faster than dragging to it.

## Keyboard

| Keys | What they do |
| --- | --- |
| ArrowRight, ArrowUp | Increase it by one step. |
| ArrowLeft, ArrowDown | Decrease it by one step. |
| Page Up, Page Down | Move by the large step, as Shift with an arrow key does. |
| Home, End | Go to the minimum and the maximum. |
| Tab | Moves through the thumbs in order. |

## Related

- [Progress](./progress.md)
- [Input](./input.md)

## Examples

What the examples import:

```tsx
import { Label, Slider, SliderValue } from "@leap-crm/design-system";
```

### With a value

Hover the thumb for its tint, drag it, or Tab to it and use the arrow keys. SliderValue shows the number in the slider's format.

```tsx
<div className="flex w-80 flex-col gap-2">
  <Label id="probability-label">Probability of instruction</Label>
  <Slider
    defaultValue={60}
    step={5}
    min={0}
    max={100}
    format={{ style: "unit", unit: "percent" }}
    aria-labelledby="probability-label"
  >
    <SliderValue />
  </Slider>
</div>
```

### Range

Two thumbs pick a range; name each one with thumbLabels.

```tsx
<div className="w-80">
  <Slider
    defaultValue={[2000, 8000]}
    min={0}
    max={10000}
    step={500}
    format={{
      style: "currency",
      currency: "AUD",
      maximumFractionDigits: 0,
    }}
    thumbLabels={["Minimum fee", "Maximum fee"]}
    aria-label="Fee range"
  >
    <SliderValue />
  </Slider>
</div>
```

### Disabled

```tsx
<div className="w-60">
  <Slider defaultValue={40} aria-label="Disabled" disabled />
</div>
```

## Props

Slider also takes ui-sdk's value, defaultValue, onValueChange, onValueCommit, min, max, step, largeStep, minStepsBetweenThumbs, orientation, disabled, readOnly, name, format and locale.

### Slider

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | Shown after the track, like a SliderValue readout. |
| `thumbLabels` | `string[]` |  | Names each thumb for screen readers when there's more than one, like ["Minimum", "Maximum"]. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### SliderValue

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
