Skip to content

Forms

NumberField

tsx
"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.

tsx
"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

tsx
"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

tsx
"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

valuenumber | null

Controlled value (null means empty).

defaultValuenumber | null

Initial value when uncontrolled.

onValueChange(value: number | null) => void

Called with the committed value.

minnumber

Lowest value. Home jumps here.

maxnumber

Highest value. End jumps here.

stepnumber

Arrow and button increment. Defaults to 1.

largeStepnumber

PageUp and PageDown increment. Defaults to step * 10.

size"sm" | "md" | "lg"

Control size. Defaults to "md".

invalidboolean

Error state; set automatically inside a <Field error>.

decrementLabelstring

Name of the decrement button (translate here). Defaults to "Decrease".

incrementLabelstring

Name of the increment button (translate here). Defaults to "Increase".

wrapperClassNamestring

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.