# Scrub Label

> Drag a numeric label to scrub its value, with pointer lock, fine and coarse modifiers, keyboard steps and rolling tabular digits.

Also known as a number scrubber.

- Tier: Eased Pro
- Interaction: Drag
- Page: https://eased.dev/components/scrub-label
- Installs: motion

## Install

Scrub Label ships with Eased Pro (https://eased.dev/#pricing). Members add the `@eased-pro` registry with their token (https://eased.dev/account), then run:

```bash
npx shadcn add @eased-pro/scrub-label
```

A numeric field you drag sideways to change, as in a design tool's inspector: dragging scrubs under pointer lock, a click types a value, and the digits roll when the value jumps.

## When to use

- Dense inspector or settings panels with many numbers: size, opacity, duration, spacing, radius.
- Values people tune by feel and want to see change live, where a Slider would take too much room.
- Fields that also need exact entry and arithmetic: a click or a typed digit opens an input that accepts `350*2` or `(80+20)/2`.

## When not to use

- Forms where people type most values: use a [Number Field](/components/number-field), which has visible steppers and an always-on input.
- A value whose position in its range is the point: use a [Slider](/components/slider).
- Touch-first screens: a horizontal drag works on touch, but there is no pointer lock and a short, fiddly target.

## Usage

```tsx example.tsx
import { useState } from "react";
import { ScrubLabel } from "@/components/eased/scrub-label/scrub-label";

export function Example() {
  const [duration, setDuration] = useState(240);
  return (
    <ScrubLabel
      label="Duration"
      value={duration}
      onChange={setDuration}
      min={0}
      max={1000}
      step={10}
      unit="ms"
    />
  );
}
```

## Examples

### Decimals and custom format

The decimals in `step` set the precision and the display. `format` formats the number only; `unit` is drawn muted after it.

```tsx
<ScrubLabel
  label="Opacity"
  value={opacity}
  onChange={setOpacity}
  min={0}
  max={1}
  step={0.01}
  format={(v) => Math.round(v * 100).toString()}
  unit="%"
/>
```

### Undo per gesture

`onChange` fires on every step while dragging. `onCommit` fires once per drag, typed commit or key press that changes the value, which is the right grain for an undo stack.

```tsx
<ScrubLabel
  label="Radius"
  value={radius}
  onChange={setRadius}
  onCommit={(v) => history.push({ radius: v })}
  min={0}
  step={1}
/>
```

### In a form

`name` adds a hidden input carrying the value, so a native form submits it. Pass `form` when the field sits outside the form element.

```tsx
<form action={saveLayer}>
  <ScrubLabel label="Width" name="width" value={width} onChange={setWidth} min={1} step={1} unit="px" />
</form>
```

## API reference

### ScrubLabel

| Prop | Type | Default | Description |
|---|---|---|---|
| `label` | `string` | | Visible name, and the field's accessible name. |
| `value` | `number` | | Controlled value. |
| `onChange` | `(value: number) => void` | | Every step change while scrubbing, a typed commit, or a key press. |
| `onCommit` | `(value: number) => void` | | Once per gesture that changes the value: drag release, typed commit or key press. A drag cancelled with `Escape`, or dragged back to where it started, commits nothing. |
| `min` / `max` | `number` | `-Infinity` / `Infinity` | Bounds. Values are clamped to them. |
| `step` | `number` | `1` | Precision and keyboard increment. Values snap to multiples of `step` counted from `min` (or from 0 when there is no `min`). |
| `format` | `(value: number, info: { step: number; decimals: number }) => string` | | Formats the number part. Default: en-US grouping at `step`'s decimals. |
| `unit` | `string` | | Shown muted after the number, e.g. `"ms"` or `"%"`. |
| `sensitivity` | `number` | `step / 2` | Value units per pixel of drag. `Shift` multiplies it by 0.1, `Alt` by 10. |
| `onDragStart` | `() => void` | | A press turns into a scrub, before the first change. |
| `onDragEnd` | `(value: number) => void` | | A scrub ends, with the final value, or the start value after `Escape`. |
| `pointerLock` | `boolean` | `true` | Lock the pointer while scrubbing with a mouse, for endless travel and a virtual cursor. |
| `fill` | `boolean` | `true` | Shade the part of the field the value covers within `min` to `max`. Needs both bounds. |
| `name` | `string` | | Submit the value with a native form through a hidden input. |
| `form` | `string` | | The id of the form the hidden input belongs to. |
| `disabled` | `boolean` | `false` | No dragging, typing or keys; removed from the tab order. |
| `focusableWhenDisabled` | `boolean` | `false` | Keeps a disabled field in the tab order, announced as disabled, e.g. so a tooltip can explain why. |
| `className` | `string` | `""` | Appended to the root's classes. The root is full width at the medium control height. |

A press becomes a scrub after 3px of travel; less than that is a click, which opens the input. Typed values accept `+ - * /`, parentheses and `×` or `x` for multiply when a number follows it (`2x4`, `10 × 2`), and drop other characters, so `1,200` reads as 1200, `240 ms` as 240 and `350px` as 350. The root carries `data-dragging` while scrubbing, and the whole page shows the `ew-resize` cursor.

## Keyboard

| Key | Action |
|---|---|
| `→` / `↑` | Increase by `step` (`Alt`: ×10). |
| `←` / `↓` | Decrease by `step` (`Alt`: ×10). |
| `PageUp` / `PageDown` | Increase or decrease by 10 steps. |
| `Home` / `End` | Jump to `min` or `max`, when that bound is set. |
| `Enter` | Opens the input with the value selected. |
| A digit, `-` or `.` | Opens the input starting with that character. |
| `Enter` (input) | Commits the typed value. An invalid entry shakes and stays open. |
| `Escape` (input) | Cancels the edit. |
| `Escape` (dragging) | Cancels the drag and restores the start value. Under pointer lock the browser takes the first `Escape` to release the lock; the drag continues from the real cursor. |
| `Shift` / `Alt` (dragging) | Fine (×0.1) or coarse (×10) scrubbing while held. |

## Accessibility

- The field is a `role="spinbutton"` named by `label`, with `aria-valuenow`, `aria-valuemin` and `aria-valuemax` (only for finite bounds) and an `aria-valuetext` that includes the unit, e.g. "240 ms".
- While typing, the spinbutton role is removed and a real `<input inputmode="decimal">` takes its place, labelled by the visible label. Committing or cancelling returns focus to the field; clicking away commits a valid value and keeps focus where it went.
- The rolling digits, fill and modifier chip are `aria-hidden`; assistive tech reads the value text.
- A pointer press focuses the field without drawing the focus ring; the next key press brings the ring back.
- Touch: the field is `touch-pan-y`, so a vertical swipe still scrolls the page and a horizontal one scrubs. Pointer lock is only requested for mouse input.

## Motion

Digits are 0 to 9 columns that slide on the `snappy` spring, so a typed value or a key press rolls instead of blinking; while dragging they change in place so the number tracks the pointer. The range fill scales on `snappy` too (instant while dragging), and brightens from 35% to 60% on hover and to full while scrubbing. Pushing past a bound leans the number into the wall, approaching 6px the further you push, and it springs back on `snappy` when you reverse or let go. A key press at a bound bumps it 3px and back (200ms), and an invalid typed value shakes it (300ms). Holding `Shift` or `Alt` mid-drag pops in a "×0.1" or "×10" chip on `snappy`, leaving in 100ms. Under pointer lock a virtual cursor follows the drag and wraps around the window's edges. Reduced motion: digits and fill change at once, there is no edge lean, bump or shake, and the chip appears without animating.

## Notes for AI

Pick Scrub Label for compact numeric inspector fields where dragging is the main way to adjust and typing is the fallback. Set `min`, `max` and `step` (its decimals set the display), `unit` for the suffix, and wire `onChange` to state and `onCommit` to history or persistence. Use `sensitivity` when a step per two pixels is too fast or too slow for the range.

Do not wrap it in another label or a spinbutton, and do not add an input beside it: it switches to its own input on click or typing, and handles keys, pointer lock, the cursor and form submission. Do not save on every `onChange` during a drag; use `onCommit`.

## Related

- [Number Field](/components/number-field): a typed numeric input with steppers.
- [Slider](/components/slider): a value shown as a position along a track.
