# Scrub input

> A bounded number input whose label can be dragged for quick adjustments while native typing stays available.

- Kind: ui · Category: Forms · Interactivity: script
- Install: `npx shadcn@latest add @haze/scrub-input`
- File: `src/components/haze/ui/scrub-input.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/scrub-input

## Use when
- A spacing or dimension control benefits from quick pointer adjustments
- A numeric setting needs precise typed values and a visible range

## Avoid when
- Use range-slider when the track itself should be the main input
- Use quantity-stepper for a shopping quantity with explicit plus and minus actions

## Alternatives
- [input](https://hazeui.com/ui/input.md)
- [range-slider](https://hazeui.com/ui/range-slider.md)
- [quantity-stepper](https://hazeui.com/ui/quantity-stepper.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Unique caller-supplied prefix for this component and its related elements. |
| name | `string` | id | no | Form submission name. |
| label | `string` | "Spacing" | no | Visible draggable label. |
| value | `number` | 24 | no | Initial numeric value. |
| min | `number` | 0 | no | Lower bound for native validation and dragging. |
| max | `number` | 100 | no | Upper bound for native validation and dragging. |
| step | `number` | 1 | no | Amount changed by each four pixels of horizontal drag. |
| unit | `string` | "px" | no | Visual unit beside the native number input. |
| disabled | `boolean` |  | no | Disables the native control and its enhancement. |
| class | `string` |  | no | Additional classes for the component root. |
| ...attributes | `native control attributes` |  | no | Other attributes are forwarded to the real form control. |

## Accessibility
- The label focuses its native number input and the keyboard keeps the browser's standard number editing behavior.
- Dragging respects min, max, step, disabled and readonly; pointer cancellation ends the adjustment without trapping input.
- Key Tab, ArrowUp, ArrowDown: Focus the numeric field and adjust it with native number keys.
- Key Shift while dragging: Use ten times the configured pointer step.

## Agent prompts

### Install and use

Install the Haze UI component "Scrub input" with `npx shadcn@latest add @haze/scrub-input`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import ScrubInput from "@/components/haze/ui/scrub-input.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/scrub-input.md

### Customize with real content

Adapt the Haze scrub-input ui for our product. Replace the demo values of these props with our real content: id, name, label, value, min, max, step, unit, disabled, class, ...attributes. Keep the layout, the heading level rules and these accessibility details: The label focuses its native number input and the keyboard keeps the browser's standard number editing behavior. Dragging respects min, max, step, disabled and readonly; pointer cancellation ends the adjustment without trapping input. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using scrub-input, check it fits: use it when a spacing or dimension control benefits from quick pointer adjustments; a numeric setting needs precise typed values and a visible range. Avoid it when use range-slider when the track itself should be the main input; use quantity-stepper for a shopping quantity with explicit plus and minus actions. Alternatives: @haze/input, @haze/range-slider, @haze/quantity-stepper.

## Example requests that should lead here
- Add a spacing number field that supports dragging its label and typing an exact value.

## Source

```astro
---
import { ArrowLeftRight } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  id: string;
  name?: string;
  label?: string;
  value?: number;
  min?: number;
  max?: number;
  step?: number;
  unit?: string;
  disabled?: boolean;
  class?: string;
  [key: string]: unknown;
}
const { id, name = id, label = "Spacing", value = 24, min = 0, max = 100, step = 1, unit = "px", disabled, class: className, ...rest } = Astro.props;
---

<div data-haze-scrub-input class={cn("grid min-w-0 gap-2", className)}>
  <label for={id} data-scrub-label class="inline-flex w-fit min-h-6 touch-pan-y items-center gap-2 rounded-sm text-sm/5 font-medium select-none [[data-enhanced]_&]:cursor-ew-resize"><ArrowLeftRight aria-hidden="true" class="size-3.5 text-muted-foreground" />{label}</label>
  <div class="relative">
    <input {...rest} id={id} name={name} type="number" value={value} min={min} max={max} step={step} disabled={disabled} aria-describedby={`${id}-hint`} data-scrub-number class="[appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none h-10 w-full min-w-0 rounded-lg border border-frame-input bg-field pr-10 pl-3 text-sm tracking-[-0.01em] tabular-nums text-foreground transition-[border-color,background-color,box-shadow] duration-150 ease-snappy hover:border-frame-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-50 aria-invalid:border-destructive aria-invalid:focus-visible:ring-destructive/24" />
    <span aria-hidden="true" class="pointer-events-none absolute top-1/2 right-3 -translate-y-1/2 text-[0.8125rem]/5 text-muted-foreground">{unit}</span>
  </div>
  <progress data-scrub-progress aria-label={`${label} within range`} max="100" value="0" hidden class="h-1 w-full overflow-hidden rounded-full bg-muted accent-primary [&[hidden]]:hidden [&::-moz-progress-bar]:bg-primary [&::-webkit-progress-bar]:bg-muted [&::-webkit-progress-value]:rounded-full [&::-webkit-progress-value]:bg-primary"></progress>
  <p id={`${id}-hint`} class="text-[0.8125rem]/5 text-muted-foreground">Values in {unit}. Type a value or use the arrow keys.<span data-scrub-hint hidden> Drag the label to adjust; hold Shift for larger steps.</span></p>
</div>

<script>
  function initScrubInputs() {
    document.querySelectorAll<HTMLElement>("[data-haze-scrub-input]").forEach(root => {
      if (root.hasAttribute("data-enhanced")) return;
      const input = root.querySelector<HTMLInputElement>("[data-scrub-number]");
      const label = root.querySelector<HTMLLabelElement>("[data-scrub-label]");
      const progress = root.querySelector<HTMLProgressElement>("[data-scrub-progress]");
      if (!input || !label || !progress) return;
      const min = Number(input.min);
      const max = Number(input.max);
      const step = Number(input.step) > 0 ? Number(input.step) : 1;
      const sync = () => { progress.value = max > min ? Math.max(0, Math.min(100, (input.valueAsNumber - min) / (max - min) * 100)) || 0 : 0; };
      let drag: { pointer: number; x: number; value: number } | null = null;
      label.addEventListener("pointerdown", event => {
        if (input.disabled || input.readOnly || event.button !== 0 || !event.isPrimary) return;
        drag = { pointer: event.pointerId, x: event.clientX, value: Number.isFinite(input.valueAsNumber) ? input.valueAsNumber : min };
        label.setPointerCapture(event.pointerId);
      });
      label.addEventListener("pointermove", event => {
        if (!drag || drag.pointer !== event.pointerId) return;
        const steps = Math.trunc((event.clientX - drag.x) / 4) * (event.shiftKey ? 10 : 1);
        const value = Math.min(max, Math.max(min, drag.value + steps * step));
        const next = String(Number(value.toFixed(8)));
        if (next === input.value) return;
        input.value = next;
        input.dispatchEvent(new Event("input", { bubbles: true }));
      });
      const end = () => { if (!drag) return; drag = null; input.dispatchEvent(new Event("change", { bubbles: true })); };
      label.addEventListener("pointerup", end);
      label.addEventListener("pointercancel", end);
      label.addEventListener("lostpointercapture", end);
      input.addEventListener("input", sync);
      input.form?.addEventListener("reset", () => queueMicrotask(sync));
      progress.hidden = false;
      root.querySelector<HTMLElement>("[data-scrub-hint]")?.removeAttribute("hidden");
      root.setAttribute("data-enhanced", "");
      sync();
    });
  }
  initScrubInputs();
  if (!document.documentElement.hasAttribute("data-haze-scrub-input-listener")) {
    document.documentElement.setAttribute("data-haze-scrub-input-listener", "");
    document.addEventListener("astro:page-load", initScrubInputs);
  }
</script>
```
