Number Field
A numeric input with stepper buttons, units, bounds and locale formatting.
Chunks returned for each query, from 1 to 10.
Usage guidelines
- Use
NumberFieldfor a precise number the user types or nudges, such as Top K, a timeout or a token limit. UseSliderwhen an approximate value within a range is enough, andInputfor numeric identifiers such as codes or phone numbers. - Put the number field in a
Fieldwith aFieldLabel; the label names the input. Without aField, giveNumberFieldInputan accessible name of its own. - Set
minandmaxwhenever the value has bounds. Stepping stops at them, and an out-of-range typed value is clamped when the input loses focus. - For whole numbers such as counts and limits, set
smallStepto thestepvalue. The defaultsmallStepof 0.1 letsAlt+ arrow keys produce decimals. - Show the unit with
NumberFieldUnitinstead of putting it in the label or the value. The unit is visual only and is not part of the input's name or description, so state the unit and the bounds in aFieldDescriptionas well. Useformatfor locale formatting such as decimals, percentages or currency. - Pass the same
sizetoNumberFieldGroup,NumberFieldInput,NumberFieldUnitand the stepper buttons.mediumis the default;largematches large inputs. - The stepper buttons are named "Increment value" and "Decrement value" by default. Pass a localized
aria-labeloraria-labelledbyin translated products. - Number fields that save together belong in a real form boundary:
Formor a native<form>, with aButtonoftype="submit".
Anatomy
NumberFieldGroup draws the input surface. NumberFieldUnit and NumberFieldControls are optional.
Examples
Sizes and units
NumberFieldUnit sits between the value and the steppers. Each FieldDescription repeats the unit and range for assistive technology. The large size uses more padding and a larger value text.
From 1 to 600 seconds.
Up to 4,096 tokens per response.
States
Set invalid on the Field when application code owns the validity, and render <FieldError match> while it is invalid; bringing the value back into range clears the error. Set disabled on Field to disable the label, input and steppers together, and readOnly on NumberField so the value stays focusable while the steppers stop.
Minimum match percentage, from 0 to 100%.
Workspace quota in requests per minute (read-only).
Managed by the workspace owner.
Step sizes and formatting
step sets the amount for the buttons and arrow keys. smallStep and largeStep set the amounts used with modifier keys. format takes Intl.NumberFormat options. The mouse wheel does not change the value unless allowWheelScrub is set, and then only while the input has focus.
From 0 to 2. Higher values make responses more varied.
Validation in a form
A required number field shows its valueMissing message when the form is submitted empty. A typed value outside min and max is clamped when the input loses focus, so the field needs no range messages.
Keyboard
| Key | Action |
|---|---|
| Up arroworDown arrow | Increases or decreases the value by step, stopping at min and max. |
| Shift+Up arroworShift+Down arrow | Steps by largeStep (10 by default). |
| Alt+Up arroworAlt+Down arrow | Steps by smallStep (0.1 by default). |
| HomeorEnd | Sets the value to min or max, when that bound is set. |
| Tab | Moves focus out of the input and commits a typed value, clamped to the bounds. The stepper buttons are not in the tab order. |
API reference
NumberField
Groups all parts of a numeric input with increment and decrement controls. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
id | string | No default | |
min | number | No default | |
max | number | No default | |
allowOutOfRange | boolean | false | |
smallStep | number | 0.1 | |
step | number | "any" | 1 | |
largeStep | number | 10 | |
required | boolean | false | |
disabled | boolean | false | |
readOnly | boolean | false | |
name | string | No default | |
form | string | No default | |
value | number | null | No default | |
defaultValue | number | No default | |
allowWheelScrub | boolean | false | |
snapOnStep | boolean | false | |
format | Intl.NumberFormatOptions | No default | |
onValueChange | ((value: number | null, eventDetails: BaseNumberField.Root.ChangeEventDetails) => void) | No default | |
onValueCommitted | ((value: number | null, eventDetails: BaseNumberField.Root.CommitEventDetails) => void) | No default | |
locale | Intl.LocalesArgument | No default | |
inputRef | React.Ref<HTMLInputElement> | No default | |
className | string | ((state: NumberFieldRootState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, NumberFieldRootState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: NumberFieldRootState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-scrubbing | Present while scrubbing. |
data-disabled | Present when the number field is disabled. |
data-readonly | Present when the number field is readonly. |
data-required | Present when the number field is required. |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). |
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). |
data-filled | Present when the number field is filled (when wrapped in Field.Root). |
data-focused | Present when the number field is focused (when wrapped in Field.Root). |
NumberFieldControls
Accepts the props of the element it renders.
NumberFieldDecrement
A stepper button that decreases the field value when clicked. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
size | 'large' | 'medium' | 'medium' | |
className | string | ((state: NumberFieldDecrementState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, NumberFieldDecrementState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: NumberFieldDecrementState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
| Attribute | Description |
|---|---|
data-scrubbing | Present while scrubbing. |
data-disabled | Present when the number field is disabled. |
data-readonly | Present when the number field is readonly. |
data-required | Present when the number field is required. |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). |
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). |
data-filled | Present when the number field is filled (when wrapped in Field.Root). |
data-focused | Present when the number field is focused (when wrapped in Field.Root). |
NumberFieldGroup
Groups the input with the increment and decrement buttons. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
size | 'large' | 'medium' | 'medium' | |
className | string | ((state: NumberFieldGroupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, NumberFieldGroupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: NumberFieldGroupState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-scrubbing | Present while scrubbing. |
data-disabled | Present when the number field is disabled. |
data-readonly | Present when the number field is readonly. |
data-required | Present when the number field is required. |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). |
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). |
data-filled | Present when the number field is filled (when wrapped in Field.Root). |
data-focused | Present when the number field is focused (when wrapped in Field.Root). |
NumberFieldIncrement
A stepper button that increases the field value when clicked. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
size | 'large' | 'medium' | 'medium' | |
className | string | ((state: NumberFieldIncrementState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, NumberFieldIncrementState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: NumberFieldIncrementState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
| Attribute | Description |
|---|---|
data-scrubbing | Present while scrubbing. |
data-disabled | Present when the number field is disabled. |
data-readonly | Present when the number field is readonly. |
data-required | Present when the number field is required. |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). |
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). |
data-filled | Present when the number field is filled (when wrapped in Field.Root). |
data-focused | Present when the number field is focused (when wrapped in Field.Root). |
NumberFieldInput
The native input control in the number field. Renders an <input> element.
| Prop | Type | Default | Details |
|---|---|---|---|
size | 'large' | 'medium' | 'medium' | |
className | string | ((state: NumberFieldInputState) => string | undefined) | No default | |
render | ComponentRenderFn<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, NumberFieldInputState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: NumberFieldInputState) => React.CSSProperties | undefined) | No default | |
aria-roledescription | string | 'Number field' | |
| Attribute | Description |
|---|---|
data-scrubbing | Present while scrubbing. |
data-disabled | Present when the number field is disabled. |
data-readonly | Present when the number field is readonly. |
data-required | Present when the number field is required. |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). |
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). |
data-filled | Present when the number field is filled (when wrapped in Field.Root). |
data-focused | Present when the number field is focused (when wrapped in Field.Root). |
NumberFieldUnit
| Prop | Type | Default | Details |
|---|---|---|---|
size | 'large' | 'medium' | 'medium' | |