Number Field
Edit a numeric value with typing, stepping or scrubbing.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/number-fieldComplete the one-time setup first. Registry JSON lists source files and dependencies.
For this page’s examples, also install:
pnpm dlx shadcn@4.18.0 add @siteplane/button @siteplane/form @siteplane/inputField is installed with Input.
Usage
import {
NumberField,
NumberFieldScrubArea,
NumberFieldGroup,
NumberFieldDecrement,
NumberFieldInput,
NumberFieldIncrement,
} from "@/siteplane/components/number-field";
<NumberField defaultValue={1}>
<NumberFieldScrubArea label="Quantity" />
<NumberFieldGroup>
<NumberFieldDecrement aria-label="Decrease quantity" />
<NumberFieldInput />
<NumberFieldIncrement aria-label="Increase quantity" />
</NumberFieldGroup>
</NumberField>;Composition
NumberField
├── NumberFieldScrubArea
└── NumberFieldGroup
├── NumberFieldDecrement
├── NumberFieldInput
└── NumberFieldIncrementControlled range
Use a number or null for an empty field. Min, max and step constrain edits; the application stores the value.
Formatted value
Locale and format apply to the editable value. The value remains numeric.
Variants and disabled
variant sets the control surface. Disabled prevents stepping and editing.
Sizes
Omit size to inherit the provider's control size. textSize overrides the text size separately.
Emphasized value
Use emphasized when the number is the content, such as a quantity in a cart or the seats of a plan. The value turns semibold and one text step larger. In a form with other fields, keep the regular value.
Form integration
Give the Field a name so Form submits the numeric value. min and max clamp the value, and FieldDescription explains the range. The field is compact by default; add className="w-full" to fill the form column.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
Number | sm | md | lg | xl | provider / lg | Shared dimensions. |
Number | sm | base | base for xl; otherwise CSS | Group text size. |
Number | boolean | false | Semibold value one text step larger than the field text: 16 px at sm, 18 px at md and lg, 20 px at xl. Overrides textSize. |
Number | default | elevated | inset | default | Group surface. |
Number | string | generated | Input/label association. |
Number | string | compact width | Layout and width. By default the field is two step buttons plus a 7rem value field wide (11rem at `md`); a width utility such as w-full or w-64 replaces that. |
Number | string | required | Visible associated label; scrubbing changes the number. |
value / default | number | null | uncontrolled | Controlled or initial numeric value. |
on | (value, eventDetails) => void | unset | Numeric edit callback. |
on | (value, eventDetails) => void | unset | Committed numeric edit callback. |
Root numeric range, formatting, locale, required, disabled, readOnly and form
props follow Base UI Number
Field. NumberFieldGroup
owns the shared surface; NumberFieldInput owns text editing;
Decrement/Increment use ghost icon Buttons by default and accept render, but
supply their own minus/plus children. ScrubArea must be inside NumberField and
supplies its own cursor. All styled parts accept string className.
NumberFieldPrimitive exports the foundation namespace. NumberFieldContext exports {fieldId, size, textSize?, variant} | null, default null. CursorGrowIcon accepts SVG props, defaults aria-hidden true and supplies the scrub cursor; it is not a control.
Usage notes
Arrow keys adjust the focused number. The field is compact by default, sized for quantities and counts; set a width in className for longer values. A value longer than the field ends with an ellipsis until the field has focus; then it scrolls to the caret, as in any input. Keep a visible label and accessible names for step buttons. For invalid or server-rejected values, compose Field help and errors; the numeric component does not persist or validate business rules.