npx shadcn@4.23.1 add @goop/trail-number-inputNumber input
FreeA field for a number, an amount or a quantity, typed in the reader's language or stepped with the arrow keys, for React and Tailwind CSS. Free, MIT.
What an agent sees
- NumberInputAddonWords beside a NumberInput's digits, inside its frame
import { NumberInput, NumberInputAddon } from '@/components/ui/goop/number-input';
import { Card } from '@/components/ui/goop/card';
import { Field } from '@/components/ui/goop/field';
import { Table, TableHeader, TableRow, TableHead, TableBody } from '@/components/ui/goop/table';
import { TableCellLabel, TableCell } from '@/components/ui/goop/table-cell';
import { StatusMark } from '@/components/ui/goop/status-mark';
<>
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Groceries" description="Monthly budget">
<NumberInput name="groceries" currency="EUR" defaultValue={400} min={0} step={10} />
</Field>
</ul>
</Card>
<NumberInput aria-label="Weight" defaultValue={2.5} min={0} step={0.1}>
<NumberInputAddon side="end">kg</NumberInputAddon>
</NumberInput>
<NumberInput aria-label="Rent" numeric currency="EUR" defaultValue={900} min={0} />
<NumberInput aria-label="Seats" stepper snap defaultValue={12} min={0} max={96} step={12} />
<Table aria-label="Studio supplies to reorder" columns="minmax(0, 1fr) auto 112px">
<TableHeader>
<TableRow>
<TableHead>
<TableCellLabel>Item</TableCellLabel>
</TableHead>
<TableHead>
<TableCellLabel>Stock</TableCellLabel>
</TableHead>
<TableHead>
<TableCellLabel>Order</TableCellLabel>
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>
<TableCellLabel>Recorder batteries, pack of 4</TableCellLabel>
</TableCell>
<TableCell>
<StatusMark status={{ name: 'Low', icon: 'alert-triangle', variant: 'warning' }} label="wide" />
</TableCell>
<TableCell>
<NumberInput aria-label="Order quantity of recorder batteries" name="batteries" defaultValue={6} min={0} />
</TableCell>
</TableRow>
</TableBody>
</Table>
</>Step the quantities with their − and + buttons (hold one to repeat) or the arrow keys (Shift for ten), PageUp/PageDown, Home and End; type more than is left and leave the field to see it marked and brought back; type a credit in euros. The total follows. Nothing is bought; the prices and seats are our own sample.
When to use
- A field for a number, an amount or a quantity, typed in the reader's language or stepped with the arrow keys.
- Also called: spin button or quantity input.
Installation
Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Number input on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing.
npx shadcn@4.23.1 add @goop/trail-number-inputAdd the Goop Number input to this project. The install steps are at https://goop.so/docs/install.mdUsage
import { NumberInput, NumberInputAddon } from '@/components/ui/goop/number-input';
import { Card } from '@/components/ui/goop/card';
import { Field } from '@/components/ui/goop/field';
import { Table, TableHeader, TableRow, TableHead, TableBody } from '@/components/ui/goop/table';
import { TableCellLabel, TableCell } from '@/components/ui/goop/table-cell';
import { StatusMark } from '@/components/ui/goop/status-mark';
<>
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Groceries" description="Monthly budget">
<NumberInput name="groceries" currency="EUR" defaultValue={400} min={0} step={10} />
</Field>
</ul>
</Card>
<NumberInput aria-label="Weight" defaultValue={2.5} min={0} step={0.1}>
<NumberInputAddon side="end">kg</NumberInputAddon>
</NumberInput>
<NumberInput aria-label="Rent" numeric currency="EUR" defaultValue={900} min={0} />
<NumberInput aria-label="Seats" stepper snap defaultValue={12} min={0} max={96} step={12} />
<Table aria-label="Studio supplies to reorder" columns="minmax(0, 1fr) auto 112px">
<TableHeader>
<TableRow>
<TableHead>
<TableCellLabel>Item</TableCellLabel>
</TableHead>
<TableHead>
<TableCellLabel>Stock</TableCellLabel>
</TableHead>
<TableHead>
<TableCellLabel>Order</TableCellLabel>
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>
<TableCellLabel>Recorder batteries, pack of 4</TableCellLabel>
</TableCell>
<TableCell>
<StatusMark status={{ name: 'Low', icon: 'alert-triangle', variant: 'warning' }} label="wide" />
</TableCell>
<TableCell>
<NumberInput aria-label="Order quantity of recorder batteries" name="batteries" defaultValue={6} min={0} />
</TableCell>
</TableRow>
</TableBody>
</Table>
</>- Fits: list (its recipe).
- Also known as: Input type="number", NumberField, CurrencyInput, Spinbutton.
- It is as wide as its container, up to 340 px: in a table cell, a grid track or a box with a width it takes that width down to 68 px, so in a 96 px column it is 96 px and never covers the next column; beside a Field row's words it is the text field's 180 px. Give its column the room the number needs; write no width class.
width="fixed"keeps it 180 px at every width (a form's column of equal fields). For a quantity bought in packs,stepper step={12} min={0} snapdraws − and + that move one case of 12 and bring a typed 13 to 12, so write no buttons of your own beside it. An editable quantity in a table row is the field straight in its cell, named by its row (aria-label="Order quantity of …"). - height, width, padding, gap, corner, border, background, text, motion: add no class for these.
API reference
| Option | Type | What it does |
|---|---|---|
| Defaults | inputMode = 'decimal' |
- Each option with its sentence: number-input--options.md
- State: value (value / defaultValue / onValueChange)
| Part | What it is |
|---|---|
| NumberInputAddon | Words beside a NumberInput's digits, inside its frame; side: start (default), end |
- Class recipes (cva): numberInputAddonVariants (NumberInputAddon)
- data-slot values (to select a part by): number-input, number-input-addon, number-input-control, number-input-frame
NumberInput: every option
import { NumberInput } from '@/components/ui/goop/number-input';Options
- value?: number | null — The number, controlled:
nullfor an empty field. - defaultValue?: number | null — The number at first, uncontrolled (empty if left out).
- onValueChange?: (value: number | null) => void — Called with each number typed in range or stepped,
nullwhen emptied. - min?: number — The lowest number; a lower one is marked invalid, then raised to it.
- max?: number — The highest number; a higher one is marked invalid, then lowered to it.
- step?: number = 1 — How far an arrow key or a stepper button moves the number; Shift, PageUp and PageDown move ten.
- stepper?: boolean = false — Draws a − and a + button at the frame's ends, each moving the number one step and repeating while held.
- snap?: boolean = false — Brings a typed number to the nearest step when it is kept.
- decreaseLabel?: string = 'Decrease' — The − button's spoken name.
- increaseLabel?: string = 'Increase' — The + button's spoken name.
- currency?: string — An amount in this currency, an ISO 4217 code (
"EUR"). - locale?: string — The language of the numbers (a BCP 47 tag); the reader's own if left out.
- format?: (value: number) => string — How the number reads at rest and when spoken ("60%"); grouped digits by default.
- numeric?: boolean — Lays the digits at the field's end, for a column of amounts.
- width?: 'fill' | 'fixed' = 'fill' —
fill: its container's width, 68 to 340 px (a table cell's whole width). - children?: ReactNode — Words beside the digits:
NumberInputAddonparts (a unit, a sign). - Also takes: onChange?: (event: ChangeEvent<HTMLInputElement>) => void; name?: string; required?: boolean; disabled?: boolean; form?: string
- Defaults: inputMode = 'decimal'
- State: value (value / defaultValue / onValueChange)
Keyboard
| Key | What it does |
|---|---|
| ArrowUp ArrowDown | Raise or lower the number by one step; with Shift, ten steps |
| PageUp PageDown | Raise or lower the number by ten steps |
| Home | Set the lowest number, where one is set |
| End | Set the highest number, where one is set |
| Enter | Keep the typed number, brought inside the range |
Accessibility
- The native element answers the keyboard.
- hover, active, focus-within: the browser's own (:hover, :active, :focus-within): write nothing
Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:
| State | Drawn by |
|---|---|
| disabled | the prop disabled |
Motion
- The part sets its own motion: add no transition or animation of your own.
- How the theme moves, and how to move your own parts the same way: Motion.
Notes for AI
Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.