This page as markdown: /scrub-field.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt
ScrubField
Status: stable
The compact numeric field a property grid is built from: a leading glyph inside the field that doubles as a drag-to-scrub handle, the value, and an optional unit.
Keywords: scrub, numeric, number, field, property, inspector, drag, workspace, tool, unit
Usage
Use ScrubField for numeric properties in tool chrome — an inspector, a property grid, a panel. The leading icon or letter says what the number is and is also the thing you drag, which is why a value like opacity needs no slider. Reach for NumberField instead in page-register forms: it has steppers and locale formatting, and it renders at page-register height. Those two steppers put a ~112px floor on a control that needs to be about 44px in a property grid, which is why ScrubField exists rather than a NumberField size variant. The input is sized in ch, so each field is as wide as its longest value and a grid of them lines up without per-field tuning.
Best practices
- Do: Give the field an icon or prefix when it stands alone, so the row has a drag affordance and the value has an identity.
- Do: Pass the unit as
suffixrather than baking it into the label — it renders against the number the way reference tools show 100%. - Do: Bracket undo with onGestureStart/onGestureEnd. A scrub fires per frame, so without it one undo rewinds a single pixel of the drag.
- Do: Set
stepto the real precision (0.01 for a normalised threshold). Display precision follows it, so a seed shows 1234 and never 1,234. - Don't: Add a separate drag gripper beside the glyph. The icon or prefix already is the scrub handle; a second one is the same affordance twice and costs width a 240px panel does not have.
- Don't: Pair it with a Slider AND give it a glyph. The slider is already the drag affordance; two on one row is the same gesture twice. Omit icon/prefix when there's a slider. For a value with both bounds, SliderField is that pair as one control.
- Don't: Use it in a page form. It is chrome-sized and has no label, description, or error slots — that's Field plus Input or NumberField.
Props
| Name | Type | Default | Description |
|---|---|---|---|
| value | number | — | The current value (controlled). |
| onValueChange | (next: number) => void | — | Fires on commit, arrow-key step, and every frame of a scrub. |
| min | number | — | Lower clamp, applied to typing and scrubbing. |
| max | number | — | Upper clamp, applied to typing and scrubbing. |
| step | number | 1 | Arrow-key and scrub increment, and the source of display precision. Shift multiplies arrows by 10 and divides scrubbing by 10. |
| label | string | — | Accessible name for the input. Required — the visible glyph is decorative. |
| icon | string | — | Semantic icon name rendered inside the field; doubles as the scrub handle. Any name the app's IconProvider resolves works — image tools typically supply their own checkerboard glyph for opacity, which is a domain icon rather than one Sable's contract carries. |
| prefix | ReactNode | — | Short text used instead of an icon (e.g. "X" / "Y"), with the same scrub role. |
| suffix | ReactNode | — | Unit rendered after the value inside the field (e.g. "%", "px"). |
| onGestureStart | () => void | — | Fires once when a scrub drag begins — open an undo transaction here, and drop expensive downstream work (e.g. a GPU renderer) to a cheap preview quality; without it a pipeline re-renders at full quality on every pointer move and the drag stutters. |
| onGestureEnd | () => void | — | Fires when a scrub drag ends — close the undo transaction here and restore full render quality. |
| disabled | boolean | — | Disables typing and scrubbing; a disabled field submits nothing, like a native control. |
| readOnly | boolean | — | Blocks typing, arrow keys and scrubbing. The value still submits. |
| name | string | — | Submits the value with a form under this name, through a hidden input: a plain number at the precision of step ("60", "0.25") — no unit, no separators. It is always the last committed value, never the draft being typed. |
| form | string | — | Id of a form elsewhere on the page that the hidden input belongs to. |
| id | string | — | Input id, for a PropertyRow's htmlFor. |
| className | string | — | Sizes the field shell (w-16, flex-1). Defaults to w-full. |
| dragLabel | (label: string) => string | (label) => Drag to change ${label} |
The scrub handle's tooltip, given label. Translate it with the rest of the panel. |
| ...props | ComponentPropsWithRef<"input"> | — | ref, aria-describedby, aria-invalid, required, data-* and handlers land on the input, so a Field's description and error reach it and a ref can focus it. |
Tokens used
foreground, muted-foreground, ring, panel-field, panel-field-hover
Motion
- arrival · Root · no motion — It arrives with the inspector row it sits in.
- response · Root ·
motion-interactive— The shell eases its focus ring like every field, so tabbing through a column of numbers shows where the keyboard is without flicker. - response · Handle ·
motion-interactive— The handle's ink brightens while the field is hovered. It is the only sign that the icon or prefix can be dragged, which nobody would guess from a label. - transition · Value · no motion — The number follows the drag pixel for pixel. Easing it — or rolling it with a NumberTicker — would show a value the pointer has already left, in a control whose whole point is precision.
- activity · Root · no motion — Scrubbing is synchronous; there is nothing to wait for.
Accessibility
- The input carries the accessible name via
label; the glyph is aria-hidden because it is decorative. - Every scrub gesture is reachable from the keyboard: ArrowUp/ArrowDown step by
step, Shift+Arrow by ten steps. - Enter commits, Escape reverts to the last committed value, and blur commits — so a partial edit is never silently kept.
- Inside a Field the id, aria-describedby, aria-invalid and required it clones reach the input, so the description and error are announced with it.
Related
- Components: NumberField, Slider, SliderField, PanelSection, Workspace, Input
Examples
In a form (submits the committed number)
import { ScrubField } from "@sableui/react"
<form action={save}>
<ScrubField label="Opacity" name="opacity" icon="grid" suffix="%" value={opacity} min={0} max={100} onValueChange={setOpacity} />
</form>
Opacity with a glyph handle
import { ScrubField } from "@sableui/react"
<ScrubField label="Opacity" icon="grid" suffix="%" value={60} min={0} max={100} onValueChange={(v) => setOpacity(v)} />
X/Y offset pair (PropertyPair puts two fields on one scan line)
import { PropertyPair, ScrubField } from "@sableui/react"
<PropertyPair labels={["Offset X", "Offset Y"]}>
<ScrubField label="Offset X" prefix="X" value={x} min={-128} max={128} onValueChange={setX} />
<ScrubField label="Offset Y" prefix="Y" value={y} min={-128} max={128} onValueChange={setY} />
</PropertyPair>
No glyph — the property name is the handle
import { PropertyRow, ScrubField } from "@sableui/react"
<PropertyRow label="Block size" scrub={{ value: size, onValueChange: setSize, min: 2, max: 256 }}>
<ScrubField label="Block size" value={size} min={2} max={256} suffix="px" onValueChange={setSize} />
</PropertyRow>
Paired with a slider (no glyph — one drag affordance per row)
import { PropertyRow, ScrubField, Slider } from "@sableui/react"
<PropertyRow label="Block size" stacked>
<div className="flex items-center gap-2">
<Slider value={32} min={4} max={256} className="min-w-0 flex-1" />
<ScrubField label="Block size" value={32} min={4} max={256} step={1} suffix="px" className="w-16 shrink-0" onValueChange={(v) => setBlockSize(v)} />
</div>
</PropertyRow>