NumberField
A numeric input with increment and decrement buttons. Supports ranges, steps, and number formatting.
View in Storybook (opens in a new tab)
Installation
import { NumberField } from "@ginga-ui/core";Basic usage
Limit the range with minValue and maxValue. The arrow keys also change the value.
number-field.tsx
import { NumberField } from "@ginga-ui/core";
export function BasicExample() {
return (
<NumberField label="Quantity" defaultValue={1} minValue={0} maxValue={10} />
);
}Icons
Pass icons to decrementIcon and incrementIcon to replace the default signs.
number-field.tsx
import { NumberField } from "@ginga-ui/core";
import { Minus, Plus } from "lucide-react";
export function IconExample() {
return (
<NumberField
label="Guests"
defaultValue={2}
minValue={1}
decrementIcon={<Minus />}
incrementIcon={<Plus />}
/>
);
}Formatting
Use formatOptions to format the value, for example as currency. step sets the increment.
Specify in steps of $0.50
number-field.tsx
import { NumberField } from "@ginga-ui/core";
export function FormatExample() {
return (
<NumberField
label="Price"
defaultValue={15}
step={0.5}
formatOptions={{ style: "currency", currency: "USD" }}
description="Specify in steps of $0.50"
/>
);
}Disabled
Pass disabled to disable the field.
number-field.tsx
import { NumberField } from "@ginga-ui/core";
export function DisabledExample() {
return <NumberField label="Quantity" defaultValue={3} disabled />;
}Props
NumberField
| Name | Type | Default | Description |
|---|---|---|---|
label | string | - | Label shown above the field. |
placeholder | string | - | Placeholder text of the input. |
description | ReactNode | - | Help text shown below the field. |
errorMessage | ReactNode | ((validation: ValidationResult) => ReactNode) | - | Error message shown when the value is invalid. |
disabled | boolean | false | Disables the field. |
required | boolean | false | Requires a value. |
readOnly | boolean | false | Makes the field read-only. |
invalid | boolean | false | Shows the field as invalid. |
decrementIcon | ReactNode | - | Icon of the decrement button. A minus sign is drawn when omitted. |
incrementIcon | ReactNode | - | Icon of the increment button. A plus sign is drawn when omitted. |
Also accepts the props of React Aria's NumberField (opens in a new tab).