# Slider

Picks a number or a range on a scale, such as years of experience or salary.

This is the HTML to build it with `dex.css`, for work outside the Dex codebase. Read https://brand.meetdex.ai/design.md first: it says how to set up a page and how to use the stylesheet. The page at https://brand.meetdex.ai/components/slider shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

A native range input. Set `--value` to where the thumb sits along the track, from 0 to 100, and keep it in step as it moves:

```html
<div class="dex-slider-label"><span id="years">Years of experience</span><span>8</span></div>
<input
  type="range" class="dex-slider" min="0" max="20" value="8" style="--value: 40"
  aria-labelledby="years"
  oninput="this.style.setProperty('--value', (this.value - this.min) / (this.max - this.min) * 100)"
/>
```

- **Range**: two inputs in a `dex-slider-range`, which draws the track. Set `--from` and `--to` on it (each 0–100) as the thumbs move, and name each thumb.

```html
<div class="dex-slider-label"><span>Salary</span><span>£95k – £130k</span></div>
<div class="dex-slider-range" style="--from: 30; --to: 53">
  <input type="range" class="dex-slider" min="50" max="200" step="5" value="95" aria-label="Salary minimum" />
  <input type="range" class="dex-slider" min="50" max="200" step="5" value="130" aria-label="Salary maximum" />
</div>
```

- **Step labels**: a `dex-slider-steps` under the track, each label at `--at` (0–100). The first and last line up with the track's ends.

```html
<div class="dex-slider-steps" aria-hidden="true">
  <span style="--at: 0">0</span><span style="--at: 50">10</span><span style="--at: 100">20+</span>
</div>
```

- **Not set**: `dex-slider--unset` for no answer yet. No fill, the thumb waits at the start with the rest edge, and the value in the label row reads "Not set".
- **Invalid**: `aria-invalid="true"` on the input (on either input of a range) turns the thumb edges red, with a `dex-field-error` 8px below. Only when the slider is required and still not set.
- **Disabled**: the `disabled` attribute dims it to 50%. Dim its label row to match (`style="opacity: 0.5"`).

## States

- Hover: the track steps up from 25% to 50%.
- Focus marks the thumb, not the track: its primary edge doubles. Held, the thumb fills.

## Rules

- Always show the value above the track, in a row with the label on the left and the value on the right.
- Name every thumb: `aria-labelledby` for one, an `aria-label` each for a range ("Salary minimum", "Salary maximum").
- For money, add two fields beside the slider so people can type an exact figure, and keep them in step with it.
- The thumbs of a range can meet. Keep the minimum at or below the maximum in your script.
