Scrub input
A bounded number input whose label can be dragged for quick adjustments while native typing stays available.
pnpm dlx shadcn@latest add @haze/scrub-input---
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>When to use
- A spacing or dimension control benefits from quick pointer adjustments
- A numeric setting needs precise typed values and a visible range
When not to use
- 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
Installation
Add the Haze registry to components.json once, then install Scrub input with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/scrub-inputnpx shadcn@latest add @haze/scrub-inputyarn dlx shadcn@latest add @haze/scrub-inputbunx --bun shadcn@latest add @haze/scrub-inputFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique caller-supplied prefix for this component and its related elements. |
| name | string | id | Form submission name. |
| label | string | "Spacing" | Visible draggable label. |
| value | number | 24 | Initial numeric value. |
| min | number | 0 | Lower bound for native validation and dragging. |
| max | number | 100 | Upper bound for native validation and dragging. |
| step | number | 1 | Amount changed by each four pixels of horizontal drag. |
| unit | string | "px" | Visual unit beside the native number input. |
| disabled | boolean | – | Disables the native control and its enhancement. |
| class | string | – | Additional classes for the component root. |
| ...attributes | native control attributes | – | Other attributes are forwarded to the real form control. |
Keyboard interactions
- Tab, ArrowUp, ArrowDown
- Focus the numeric field and adjust it with native number keys.
- Shift while dragging
- Use ten times the configured pointer step.
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.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
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": "http://localhost:4329/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: http://localhost:4329/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.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.