Number Field

Web/Mobile

A labeled number field with icons, stepper arrows, description, and error. inputMode is locked to numeric; values always display as Persian digits.

فقط عدد وارد کنید. با فلش‌ها مقدار را کم یا زیاد کنید.

Installation

pnpm dlx cubix-ui@latest add number-field

Usage

Import
import {
  NumberField,
  NumberFieldControl,
  NumberFieldDescription,
  NumberFieldInput,
  NumberFieldLabel,
  NumberFieldStepper,
} from "@/components/cubix/number-field"
Example
<NumberField className="w-full max-w-sm">
  <NumberFieldLabel>تعداد</NumberFieldLabel>
  <NumberFieldControl>
    <Icon data-icon="inline-start" />
    <NumberFieldInput defaultValue="۱۲" placeholder="۰" />
    <NumberFieldStepper />
  </NumberFieldControl>
  <NumberFieldDescription>
    فقط عدد وارد کنید. با فلش‌ها مقدار را کم یا زیاد کنید.
  </NumberFieldDescription>
</NumberField>

Composition

Same composition as Text Field. Place NumberFieldStepper inside the control for up and down arrows that change the value. NumberFieldInput uses inputMode="numeric" with type="text" so values always display as Persian digits; Latin and Arabic-Indic digits are converted as they are typed or pasted.

Structure
NumberField
├── NumberFieldLabel
├── NumberFieldControl
│   ├── Icon data-icon="inline-start" | "inline-end"
│   ├── NumberFieldInput
│   └── NumberFieldStepper
├── NumberFieldDescription
└── NumberFieldError

Accessibility

ArrowUp and ArrowDown on the input step the value by step and respect min and max, so the stepper buttons stay out of the tab order without losing keyboard access. The buttons are named by incrementLabel and decrementLabel. NumberFieldDescription and NumberFieldError are announced through aria-describedby.

Examples

Stepper

NumberFieldStepper renders up and down arrows that increase or decrease the value. Set min, max, and step on the input to bound both the arrows and the keyboard.

بین ۱ تا ۱۰ نفر.

Description

Add helper text below the input for format hints or guidance.

مقدار باید یک عدد صحیح باشد.

Invalid

Set invalid on the root to apply destructive styles and show NumberFieldError.

تعداد باید حداقل ۱ باشد.

Disabled

Disable the field to block the input and stepper. The control uses a muted fill; label and description stay readable.

این فیلد فعلاً قابل ویرایش نیست.

Sizes

Two heights ship by default: default (40px) and lg (48px). Use className for any other size.

ارتفاع ۴۰ پیکسل

ارتفاع ۴۸ پیکسل

Icons

Place icons inside NumberFieldControl with data-icon like Button so spacing follows the reading direction.

In a form

Set name on the root so the value is submitted with the form, and pair the field with Cubix Button.

ثبت سفارش

تعداد مورد نظر را وارد کنید.

حداقل ۱ عدد.

Custom styling

Every part accepts a className merged with the shipped cn helper. Here the field uses a filled surface instead of the default outline.

با className می‌توانید ظاهر را سفارشی کنید.

API Reference

Note: Parts render data-slot attributes (number-field, number-field-label, number-field-control, number-field-input, number-field-stepper, number-field-increment, number-field-decrement, number-field-description, number-field-error) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.

NumberField

PropTypeDefaultDescription
size"default" | "lg""default"Height for the input: default 40px, lg 48px. Inherited by NumberFieldInput and NumberFieldControl unless overridden. Use className for other heights.
disabledbooleanfalseDisables the field and prevents interaction. Forwarded to the control on every base.
invalidbooleanfalseMarks the field as invalid and shows NumberFieldError when present.
namestring-Identifies the field when a form is submitted. Forwarded to the input on every base.
classNamestring-Additional Tailwind classes merged with the root styles (last one wins).

NumberFieldControl

PropTypeDefaultDescription
size"default" | "lg"-Overrides the size from NumberField. Icon inset and height match the default and lg sizes.
childrenReact.ReactNode-Wrap NumberFieldInput with icons marked data-icon="inline-start" or "inline-end" (same as Button), and optionally NumberFieldStepper.
classNamestring-Additional Tailwind classes merged with the control styles (last one wins).

NumberFieldInput

PropTypeDefaultDescription
type"text""text"Always displays Persian digits (۰-۹). Latin or Arabic-Indic digits typed or pasted are converted. inputMode is always numeric and spellCheck is always false.
size"default" | "lg"-Overrides the size from NumberField. Default 40px, lg 48px. Use className for other heights.
inputMode"numeric""numeric"Locked to numeric so mobile keyboards show a number pad.
minnumber | string-Minimum value used by NumberFieldStepper when decreasing.
maxnumber | string-Maximum value used by NumberFieldStepper when increasing.
stepnumber | string1Step size used by ArrowUp / ArrowDown on the input and by NumberFieldStepper unless the stepper overrides it.
placeholderstring-Hint text shown when the input is empty.
classNamestring-Additional Tailwind classes merged with the input styles (last one wins).
...propsOmit<React.ComponentProps<'input'>, 'type' | 'inputMode' | 'spellCheck'>-Native input attributes (value, onChange, name, required, ...) are forwarded. type, inputMode, and spellCheck stay locked for numeric entry.

NumberFieldStepper

PropTypeDefaultDescription
stepnumber-Overrides the input step attribute for the arrow buttons only. Set step on NumberFieldInput to keep keyboard and buttons in sync. Defaults to 1 when neither is set.
incrementLabelstring"افزایش"Accessible name for the increase button.
decrementLabelstring"کاهش"Accessible name for the decrease button.
classNamestring-Additional Tailwind classes merged with the stepper styles (last one wins).

NumberFieldLabel / Description / Error

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the part styles (last one wins).
...propsHTML attributes-Native attributes for the rendered element are forwarded.