NumberField
"use client";
import { Field, NumberField } from "@cherry-design-system/react";
export function Guests() {
return (
<Field label="Guests">
<NumberField name="guests" min={1} max={8} defaultValue={2} />
</Field>
);
}A numeric input with decrement and increment buttons (role="spinbutton"). Typed text commits on blur or Enter, clamped to min and max and snapped to step. Use it for quantities and exact numbers. Use Range when an approximate value is enough.
Examples
Controlled
value is null when the field is empty.
"use client";
import { useState } from "react";
import { Field, NumberField } from "@cherry-design-system/react";
export function Quantity() {
const [qty, setQty] = useState<number | null>(1);
return (
<Field label="Quantity" hint={qty === null ? "Enter a quantity." : undefined}>
<NumberField value={qty} onValueChange={setQty} min={0} />
</Field>
);
}Decimal steps
"use client";
import { Field, NumberField } from "@cherry-design-system/react";
export function Weight() {
return (
<Field label="Weight (kg)">
<NumberField step={0.5} largeStep={5} min={0} defaultValue={2.5} size="sm" />
</Field>
);
}Translated button labels
"use client";
import { Field, NumberField } from "@cherry-design-system/react";
export function Personas() {
return (
<Field label="Personas">
<NumberField min={1} defaultValue={2} decrementLabel="Reducir" incrementLabel="Aumentar" />
</Field>
);
}Properties
Controlled value (null means empty).
Initial value when uncontrolled.
Called with the committed value.
Lowest value. Home jumps here.
Highest value. End jumps here.
Arrow and button increment. Defaults to 1.
PageUp and PageDown increment. Defaults to step * 10.
Control size. Defaults to "md".
Error state; set automatically inside a <Field error>.
Name of the decrement button (translate here). Defaults to "Decrease".
Name of the increment button (translate here). Defaults to "Increase".
Class for the outer wrapper (className goes to the <input>).
The ref and native <input> attributes (except size, type, value, defaultValue, min, max and step, which are typed above) go to the <input>.
Styling
Root class cherry-number-field with data-size (sm, md, lg) and states data-invalid, data-disabled. Parts: cherry-number-field__input, __button, __decrement, __increment.
Reads the field tokens (--cherry-bg-canvas, --cherry-border-default, --cherry-border-focus, --cherry-ring, --cherry-ring-danger) and --cherry-ghost-hover for the buttons.
Accessibility
role="spinbutton": Up and Down step, PageUp and PageDown use largeStep, Home and End go to min and max. The stepper buttons are labelled (decrementLabel, incrementLabel). Label the field with Field.