Quantity: 3 / 10
Installation
npx logic2b@next add number-fieldUsage
import { NumberField } from "@/components/ui/number-field"
<NumberField defaultValue={1} min={0} max={10} />
Controlled:
const [value, setValue] = React.useState(3)
<NumberField value={value} onValueChange={setValue} min={0} max={10} />
It renders a real <input type="number">, so it works with native form
submission and keyboard entry; the browser’s own spinners are hidden in favor of
the styled buttons, which disable themselves at the min/max bounds.
Examples
Step
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
<NumberField
defaultValue={3}
min={0}
max={12}
step={1}
aria-label="Quantity"
/>API reference
Generated from the public TypeScript exports in src/ui/number-field.tsx.
NumberFieldProps
Typeinterface NumberFieldProps extends Omit< React.ComponentProps<"input">, "value" | "defaultValue" | "onChange" | "type" > { value?: number defaultValue?: number onValueChange?: (value: number) => void min?: number max?: number step?: number }NumberField
ComponentA numeric input with decrement/increment steppers, min/max clamping and step. Controlled via `value`/`onValueChange` or uncontrolled via `defaultValue`. Renders a real `<input type="number">` so native form submission and keyboard work; the native spinners are hidden in favor of the styled buttons.
Props: NumberFieldProps| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
value | number | No | — | — |
defaultValue | number | No | — | — |
onValueChange | (value: number) => void | No | — | — |
min | number | No | — | — |
max | number | No | — | — |
step | number | No | 1 | — |
Accessibility contract
Machine-readable behavior and consumer responsibilities for number-field.
- Support
- Native semantics
- Pattern
- spinbutton
- HTMLInputElement type=number
| Keys | Behavior |
|---|---|
| ArrowUp ArrowDown ArrowLeft ArrowRight | Move within the composite control. |
| Enter | Commit typed input according to native number-field behavior. |
Built-in semantics
- The input retains native spinbutton semantics; step buttons are native buttons with labels.
Consumer responsibilities
- Associate the input with a label and communicate min/max constraints in visible help text.