component
NumberField
A number you nudge: minus, the value, plus, in a 48px box with Input's colours. For counts and quantities, not for prices.
Try it
Every variant
DefaultDisabledHover, press or tab to one to see the other 2 states.
import { NumberField } from 'rost/components/number-field/NumberField'
<NumberField label="Seats" value={seats} onValueChange={setSeats} min={1} max={50} /> src/components/number-field/NumberField.tsx
import { useEffect, useState, type KeyboardEvent } from 'react'
import './number-field.css'
export interface NumberFieldProps {
/** What the number counts, for screen readers: Seats. */
readonly label: string
/** The number. Controlled: pair it with `onValueChange`. */
readonly value?: number
/** Where it starts when it isn't controlled. */
readonly defaultValue?: number
readonly onValueChange?: (value: number) => void
/** The smallest it goes. */
readonly min?: number
/** The largest it goes. */
readonly max?: number
/** How much one press or one arrow key moves it. */
readonly step?: number
readonly disabled?: boolean
readonly name?: string
readonly id?: string
readonly className?: string
}
const b = 'rost-number-field'
/**
* A number you nudge: minus, the value, plus. The input is a
* `role="spinbutton"`; the buttons stay out of the Tab order, since the
* arrow keys do what they do. Built from contracts/number-field.contract.yaml.
*/
export function NumberField({ label, value, defaultValue = 0, onValueChange, min, max, step = 1, disabled = false, name, id, className }: NumberFieldProps) {
const [own, setOwn] = useState(defaultValue)
const n = value ?? own
// What's in the field while you type, read as a number when you leave it.
const [draft, setDraft] = useState<string | null>(null)
useEffect(() => { setDraft(null) }, [n])
const clamp = (x: number) => Math.min(max ?? Infinity, Math.max(min ?? -Infinity, x))
const set = (x: number) => {
const next = clamp(Number(x.toFixed(10)))
setDraft(null)
if (next === n) return
if (value === undefined) setOwn(next)
onValueChange?.(next)
}
const commit = () => {
if (draft === null) return
const x = Number(draft.trim().replace(',', '.'))
if (draft.trim() === '' || !Number.isFinite(x)) setDraft(null)
else set(x)
}
const keys: Record<string, () => void> = {
ArrowUp: () => set(n + step),
ArrowDown: () => set(n - step),
PageUp: () => set(n + step * 10),
PageDown: () => set(n - step * 10),
...(min !== undefined && { Home: () => set(min) }),
...(max !== undefined && { End: () => set(max) }),
}
const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') { commit(); return }
const go = keys[e.key]
if (!go) return
e.preventDefault()
commit()
go()
}
return (
<div className={[b, className].filter(Boolean).join(' ')}>
<button type="button" className={`${b}__decrement`} tabIndex={-1} aria-label="Decrease" disabled={disabled || (min !== undefined && n <= min)} onClick={() => set(n - step)}>
<span className={`${b}__decrement-glyph`} aria-hidden="true" />
</button>
<input
id={id}
name={name}
className={`${b}__input`}
type="text"
inputMode="decimal"
role="spinbutton"
aria-label={label}
aria-valuenow={n}
aria-valuemin={min}
aria-valuemax={max}
autoComplete="off"
disabled={disabled}
value={draft ?? String(n)}
onChange={(e) => setDraft(e.target.value)}
onBlur={commit}
onKeyDown={onKeyDown}
/>
<button type="button" className={`${b}__increment`} tabIndex={-1} aria-label="Increase" disabled={disabled || (max !== undefined && n >= max)} onClick={() => set(n + step)}>
<span className={`${b}__increment-glyph`} aria-hidden="true" />
</button>
<span className={`${b}__focus-ring`} aria-hidden="true" />
</div>
)
}
The source for everything on this page: contracts/number-field.contract.yaml (opens in a new tab). The CSS, the docs and the checks in each app are built from it.
# yaml-language-server: $schema=../schema/component-contract.schema.json
schemaVersion: 2
id: number-field
name: NumberField
kind: component
status: review
summary: "A number you nudge: minus, the value, plus, in a 48px box with Input's colours. For counts and quantities, not for prices."
category: inputs
related: [ input, slider ]
source:
tool: figma
fileKey: 1Zy0wiWKXQAvsfDBX3KR0d
nodeId: "773:81"
url: https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=773-81
extractedAt: "2026-11-30"
extractedBy: hand
frozenAt: "2026-11-30"
props:
label: { type: string, required: true, notes: "What the number counts, for screen readers: Seats. Put a visible label next to it as well, in a Fieldset or a form row." }
value: { type: number, notes: "The number. Controlled: pair it with `onValueChange`. Without it the field keeps its own, starting at `defaultValue`." }
min: { type: number, notes: "The smallest it goes. Minus switches off there." }
max: { type: number, notes: "The largest it goes. Plus switches off there." }
step: { type: number, default: 1, notes: "How much one press or one arrow key moves it." }
states: [ Default, Hover, Focus, Disabled, DecrementHover, IncrementHover, DecrementOff, IncrementOff ]
stateSelectors:
Focus: ":has(.rost-number-field__input:focus-visible)"
Disabled: ":has(.rost-number-field__input:disabled)"
DecrementHover: ":has(.rost-number-field__decrement:hover:enabled)"
IncrementHover: ":has(.rost-number-field__increment:hover:enabled)"
DecrementOff: ":has(.rost-number-field__decrement:disabled)"
IncrementOff: ":has(.rost-number-field__increment:disabled)"
elements:
root:
notes: "The box: 48px tall, 4px in all round, so the two 40px buttons sit inside its 12px corners. The edge is drawn inside."
styles:
display: { value: inline-flex, assert: false }
align-items: { value: center }
position: { value: relative, assert: false }
gap: { token: spacing/gap/2xsmall, value: 4px }
height: { token: spacing/size/medium-large, value: 48px }
width: { value: 160px, notes: "Room for five digits. It doesn't need to grow with the form." }
padding: { token: spacing/gap/2xsmall, value: 4px }
border-radius: { token: spacing/radius/medium, value: 12px }
outline-style: { value: solid, assert: false }
outline-width: { token: spacing/outline/small, value: 1px }
outline-offset: { value: "calc(-1 * var(--spacing-outline-small))", untokenised: "Composed from a token: the edge sits inside the box." }
decrement:
notes: "Minus, a 40px button with 8px corners. Out of the Tab order: the arrow keys do the same from the field."
styles:
display: { value: flex, assert: false }
align-items: { value: center }
justify-content: { value: center }
flex-shrink: { value: "0", assert: false }
width: { token: spacing/size/medium, value: 40px }
height: { token: spacing/size/medium, value: 40px }
padding: { value: "0", assert: false }
border: { value: none, assert: false }
border-radius: { token: spacing/radius/small, value: 8px }
background: { value: transparent, assert: false }
cursor: { value: pointer, assert: false }
decrement-glyph:
notes: "Rost's minus icon, 20px."
styles:
display: { value: block, assert: false }
width: { token: spacing/size/xsmall, value: 20px }
height: { token: spacing/size/xsmall, value: 20px }
mask: { value: url(./icon-minus.svg) center / contain no-repeat, untokenised: The icon file itself. }
input:
notes: "The real `<input>`, the number in the middle, paragraph type at medium weight, with figures that keep their width as the number changes."
styles:
flex: { value: 1 1 0, assert: false }
min-width: { value: "0", assert: false }
height: { value: 100%, assert: false }
padding: { value: "0", assert: false }
border: { value: none, assert: false }
background: { value: transparent, assert: false }
outline: { value: none, assert: false }
text-align: { value: center, assert: false }
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/paragraph/font-weight/medium, value: "500" }
font-size: { token: typography/paragraph/font-size, value: 14px }
line-height: { token: typography/paragraph/line-height, value: 20px }
letter-spacing: { token: typography/paragraph/letter-spacing, value: 0px }
font-variant-numeric: { value: tabular-nums, assert: false }
increment:
notes: "Plus, the same button as minus."
styles:
display: { value: flex, assert: false }
align-items: { value: center }
justify-content: { value: center }
flex-shrink: { value: "0", assert: false }
width: { token: spacing/size/medium, value: 40px }
height: { token: spacing/size/medium, value: 40px }
padding: { value: "0", assert: false }
border: { value: none, assert: false }
border-radius: { token: spacing/radius/small, value: 8px }
background: { value: transparent, assert: false }
cursor: { value: pointer, assert: false }
increment-glyph:
notes: "Rost's plus icon, 20px."
styles:
display: { value: block, assert: false }
width: { token: spacing/size/xsmall, value: 20px }
height: { token: spacing/size/xsmall, value: 20px }
mask: { value: url(./icon-plus.svg) center / contain no-repeat, untokenised: The icon file itself. }
focus-ring:
notes: "Input's ring, 4px outside the box."
styles:
display: { value: none, assert: false }
position: { value: absolute, assert: false }
inset: { value: "calc(-1 * var(--spacing-gap-2xsmall))", untokenised: "Composed from a token: the ring sits spacing/gap/2xsmall outside the box." }
border-style: { value: solid, assert: false }
border-width: { token: spacing/outline/medium, value: 2px }
border-radius: { token: spacing/radius/large, value: 16px }
pointer-events: { value: none, assert: false }
variants:
- when: { state: Default }
figmaNode: "773:40"
elements:
root:
background: { token: number-field/background, value: "#060805" }
outline-color: { token: number-field/edge, value: "#747573" }
decrement-glyph:
background: { token: number-field/step, value: "#00d669" }
input:
color: { token: number-field/value, value: "#c2c7c3" }
increment-glyph:
background: { token: number-field/step, value: "#00d669" }
- when: { state: Hover }
figmaNode: "773:50"
elements:
root:
background: { token: number-field/hover/background, value: "#171717" }
outline-color: { token: number-field/hover/edge, value: "#999999" }
decrement-glyph:
background: { token: number-field/step, value: "#00d669" }
input:
color: { token: number-field/value, value: "#c2c7c3" }
increment-glyph:
background: { token: number-field/step, value: "#00d669" }
- when: { state: Focus }
figmaNode: "773:60"
elements:
root:
background: { token: number-field/background, value: "#060805" }
outline-color: { token: number-field/edge, value: "#747573" }
decrement-glyph:
background: { token: number-field/step, value: "#00d669" }
input:
color: { token: number-field/value, value: "#c2c7c3" }
increment-glyph:
background: { token: number-field/step, value: "#00d669" }
focus-ring:
display: { value: block, assert: false }
border-color: { token: number-field/focus-ring, value: "#00d669" }
- when: { state: Disabled }
figmaNode: "773:71"
elements:
root:
background: { token: number-field/disabled/background, value: "#171717" }
outline-color: { token: number-field/disabled/edge, value: "#3a3a3a" }
decrement:
cursor: { value: default, assert: false }
decrement-glyph:
background: { token: number-field/disabled/step, value: "#b6ffda" }
opacity: { token: opacity/soft, value: "0.16", notes: "As Input's icon does when it's disabled." }
input:
color: { token: number-field/disabled/value, value: "#555555" }
increment:
cursor: { value: default, assert: false }
increment-glyph:
background: { token: number-field/disabled/step, value: "#b6ffda" }
opacity: { token: opacity/soft, value: "0.16" }
- when: { state: DecrementHover }
elements:
decrement:
background: { token: number-field/step-hover/background, value: "#006f27" }
- when: { state: IncrementHover }
elements:
increment:
background: { token: number-field/step-hover/background, value: "#006f27" }
- when: { state: DecrementOff }
elements:
decrement:
cursor: { value: default, assert: false }
decrement-glyph:
background: { token: number-field/disabled/step, value: "#b6ffda" }
opacity: { token: opacity/soft, value: "0.16", notes: "At `min`, minus looks like a disabled field's." }
- when: { state: IncrementOff }
elements:
increment:
cursor: { value: default, assert: false }
increment-glyph:
background: { token: number-field/disabled/step, value: "#b6ffda" }
opacity: { token: opacity/soft, value: "0.16" }
guidance:
status: proposed
use:
- title: Small counts
text: "Seats on a plan, copies to print, nights in a stay: whole numbers people change by one or two."
show: "state=Default"
avoid:
- title: Money and long numbers
text: "A price, an IBAN, a phone number: nobody nudges those by one. That's an **Input**."
- title: A rough amount
text: "When near enough is fine and the range is wide, a **Slider** is quicker."
behaviour: "Minus and plus move it by `step`, and switch off at `min` and `max`. You can type into it too: when you leave the field, what you typed is read as a number and kept inside `min` and `max`, and anything that isn't a number puts the last good value back."
accessibility:
element: "The input is `role=\"spinbutton\"` with `aria-valuenow`, `aria-valuemin` and `aria-valuemax`, the ARIA pattern for a number you step through. Minus and plus are `<button>`s with `tabindex=\"-1\"`, since the keys below do what they do."
name: "`label`, as `aria-label` on the input. The buttons say Decrease and Increase."
keyboard: "Up and Down step by one `step`, Page Up and Page Down by ten, Home and End go to `min` and `max` when there are any."
focus: "`focus-ring` around the box, on `:focus-visible`."
colour: "Input's: the edge is 4.3:1 on the dark page, the number 11:1."
content: "Whole numbers. Put the unit in the label (Nights), not in the field."
Install
npx github:Runceanu/rost add number-field It lands in src/rost/number-field/, with what it needs and its contract. Install has the rest.
When to use
Small counts
Seats on a plan, copies to print, nights in a stay: whole numbers people change by one or two.
When not to use
Money and long numbers
A price, an IBAN, a phone number: nobody nudges those by one. That's an Input.
A rough amount
When near enough is fine and the range is wide, a Slider is quicker.
Behaviour
Minus and plus move it by step, and switch off at min and max. You can type into it too: when you leave the field, what you typed is read as a number and kept inside min and max, and anything that isn't a number puts the last good value back.
Accessibility
- Element
The input is
role="spinbutton"witharia-valuenow,aria-valueminandaria-valuemax, the ARIA pattern for a number you step through. Minus and plus are<button>s withtabindex="-1", since the keys below do what they do. - Name
label, asaria-labelon the input. The buttons say Decrease and Increase. - Keyboard
Up and Down step by one
step, Page Up and Page Down by ten, Home and End go tominandmaxwhen there are any. - Focus
focus-ringaround the box, on:focus-visible. - Colour
Input's: the edge is 4.3:1 on the dark page, the number 11:1.
Content
Whole numbers. Put the unit in the label (Nights), not in the field.
Props
| Prop | Type | Values | Default |
|---|---|---|---|
label | string | | |
value | number | | |
min | number | | |
max | number | | |
step | number | | 1 |
States: Default, Hover, Focus, Disabled, DecrementHover, IncrementHover, DecrementOff, IncrementOff.
Values
Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.
Never changes
root
-
gap4pxspacing/gap/2xsmall -
height48pxspacing/size/medium-large -
width160pxno token yet -
padding4pxspacing/gap/2xsmall -
border-radius12pxspacing/radius/medium -
outline-width1pxspacing/outline/small -
outline-offsetcalc(-1 * var(--spacing-outline-small))on purpose: Composed from a token: the edge sits inside the box.
displayinline-flex · align-itemscenter · positionrelative · outline-stylesolid
decrement
-
width40pxspacing/size/medium -
height40pxspacing/size/medium -
border-radius8pxspacing/radius/small
displayflex · align-itemscenter · justify-contentcenter · flex-shrink0 · padding0 · bordernone · backgroundtransparent · cursorpointer
decrement-glyph
-
width20pxspacing/size/xsmall -
height20pxspacing/size/xsmall -
maskurl(./icon-minus.svg) center / contain no-repeaton purpose: The icon file itself.
displayblock
input
-
font-family'General Sans Variable'font-family/base -
font-weight500typography/paragraph/font-weight/medium -
font-size14pxtypography/paragraph/font-size -
line-height20pxtypography/paragraph/line-height -
letter-spacing0pxtypography/paragraph/letter-spacing
flex1 1 0 · min-width0 · height100% · padding0 · bordernone · backgroundtransparent · outlinenone · text-aligncenter · font-variant-numerictabular-nums
increment
-
width40pxspacing/size/medium -
height40pxspacing/size/medium -
border-radius8pxspacing/radius/small
displayflex · align-itemscenter · justify-contentcenter · flex-shrink0 · padding0 · bordernone · backgroundtransparent · cursorpointer
increment-glyph
-
width20pxspacing/size/xsmall -
height20pxspacing/size/xsmall -
maskurl(./icon-plus.svg) center / contain no-repeaton purpose: The icon file itself.
displayblock
focus-ring
-
border-width2pxspacing/outline/medium -
border-radius16pxspacing/radius/large
displaynone · positionabsolute · insetcalc(-1 * var(--spacing-gap-2xsmall)) · border-stylesolid · pointer-eventsnone
Changes by variant
8 variants. Each table is what one thing changes with: a column per state, a row per property. Where every row starts with the same token path, it's written once, under the property.
Follows state
In 4 variants
| Property | Default | Hover | Focus | Disabled |
|---|---|---|---|---|
input.colornumber-field/… | value #c2c7c3 | value #c2c7c3 | value #c2c7c3 | disabled/value #555555 |
root.backgroundnumber-field/… | background #060805 | hover/background #171717 | background #060805 | disabled/background #171717 |
root.outline-colornumber-field/… | edge #747573 | hover/edge #999999 | edge #747573 | disabled/edge #3a3a3a |
In 5 variants
| Property | Default | Hover | Focus | Disabled | DecrementOff | IncrementOff |
|---|---|---|---|---|---|---|
decrement-glyph.backgroundnumber-field/… | step #00d669 | step #00d669 | step #00d669 | disabled/step #b6ffda | disabled/step #b6ffda | · |
increment-glyph.backgroundnumber-field/… | step #00d669 | step #00d669 | step #00d669 | disabled/step #b6ffda | · | disabled/step #b6ffda |
Only in some variants
These don't change: they're just set in some variants and not others.
In 2 variants
-
decrement-glyph.opacity0.16opacity/soft -
decrement.cursordefaultFigma frame size -
increment-glyph.opacity0.16opacity/soft -
increment.cursordefaultFigma frame size
DecrementHover
-
decrement.background#006f27number-field/step-hover/background
Focus
-
focus-ring.border-color#00d669number-field/focus-ring -
focus-ring.displayblocklayout
IncrementHover
-
increment.background#006f27number-field/step-hover/background