#InputNumber
Enter numeric values such as quantities or prices.
#Basic usage
basic.tsx
import { Form, FormField, InputNumber, Text } from '@ifhover/leaf-ui';
import { useState } from 'react';
export function InputNumberBasic() {
const [value, setValue] = useState<number | null>(3);
return (
<Form layout="vertical">
<FormField label="Quantity">
<InputNumber name="quantity" min={0} max={20} value={value} onChange={setValue} />
</FormField>
<FormField label="Price">
<InputNumber min={0} step={0.1} precision={2} defaultValue={19.9} prefix="¥" />
</FormField>
<FormField label="Percentage">
<InputNumber defaultValue={50} min={0} max={100} suffix="%" controls={false} />
</FormField>
<FormField label="Read only">
<InputNumber defaultValue={12} readOnly />
</FormField>
<FormField label="Disabled">
<InputNumber defaultValue={8} disabled />
</FormField>
<Text tone="muted">Current quantity: {value ?? 'Empty'}</Text>
</Form>
);
}
#Formatting and exact decimals
capabilities.tsx
import { Form, FormField, InputNumber } from '@ifhover/leaf-ui';
export function Capabilities() {
return (
<Form layout="vertical">
<FormField label={'Grouped amount'}>
<InputNumber defaultValue={12345.67} precision={2} grouping prefix="$" />
</FormField>
<FormField label={'Exact decimal string'}>
<InputNumber
stringMode
name="amount"
defaultValue="9007199254740993.01"
step="0.01"
precision={2}
/>
</FormField>
<FormField label={'Custom percent format'}>
<InputNumber
defaultValue={15}
min={0}
max={100}
formatter={(value) => (value == null ? '' : `${value}%`)}
parser={(text) => text.replace('%', '')}
/>
</FormField>
</Form>
);
}
#InputNumber API
| Property | Type | Default | Description |
|---|---|---|---|
value | number | null | string | null | null | Controlled / initial value; null is empty |
defaultValue | number | null | string | null | null | Controlled / initial value; null is empty |
onChange | ((value: number | null) => void) | ((value: string | null) => void) | — | Called for a valid number or clearing |
min | number | string | Unbounded | Allowed number range |
max | number | string | Unbounded | Allowed number range |
step | number | string | 1 | Increment and decrement step |
precision | number | — | Decimal precision, from 0 to 15 |
controls | boolean | true | Show increment and decrement buttons |
keyboard | boolean | true | Support arrow key increments |
size | 'sm' | 'md' | 'lg' | 'md' | Control size |
status | 'error' | 'warning' | — | Validation status |
prefix | ReactNode | — | Leading / trailing decoration |
suffix | ReactNode | — | Leading / trailing decoration |
stringMode | false | true | — | Use strings for exact values, steps and bounds. |
formatter | ( value: number | string | null, info: { userTyping: boolean; input: string }, ) => string | — | Format displayed text without changing the canonical form value. |
parser | (text: string) => number | string | — | Parse displayed text back into a value. |
grouping | boolean | — | Use localized digit grouping. |
locale | string | — | Locale for language or numeric formatting. |
disabled | boolean | false | Disable interaction. |
readOnly | boolean | false | Lock the value against typing, selection, clearing and removal. |
ref | Ref<HTMLInputElement> | — | Input element ref |
#Types
Import the component props and item types when preparing your own values.
import type { InputNumberProps } from '@ifhover/leaf-ui';#Usage notes
Partial minus signs and decimal points are preserved during typing. Blur or Enter normalizes the range and precision; stepping avoids common decimal accumulation errors. Use name for FormData submission. required, form and autoComplete reach the input, and form reset is supported. className and style apply to the wrapper.
#NumericInputNumber API
| Property | Type | Default | Description |
|---|---|---|---|
value | number | null | — | Controlled value. |
defaultValue | number | null | null | Initial value; uncontrolled fields support native form reset. |
onChange | (value: number | null) => void | — | Called when the value changes. |
min | number | — | Minimum allowed value. |
max | number | — | Maximum allowed value. |
step | number | 1 | Step; Slider uses only marked values when null. |
precision | number | — | Decimal precision. |
controls | boolean | true | Configure controls. |
keyboard | boolean | true | Configure keyboard. |
size | 'sm' | 'md' | 'lg' | 'md' | Presentation size. |
status | 'error' | 'warning' | — | Configure status. |
prefix | ReactNode | — | Leading content. |
suffix | ReactNode | — | Trailing content. |
stringMode | false | — | Use strings for exact values, steps and bounds. |
formatter | ( value: number | string | null, info: { userTyping: boolean; input: string }, ) => string | — | Format displayed text without changing the canonical form value. |
parser | (text: string) => number | string | — | Parse displayed text back into a value. |
grouping | boolean | — | Use localized digit grouping. |
locale | string | — | Locale for language or numeric formatting. |
#StringInputNumber API
| Property | Type | Default | Description |
|---|---|---|---|
precision | number | — | Decimal precision. |
controls | boolean | true | Configure controls. |
keyboard | boolean | true | Configure keyboard. |
size | 'sm' | 'md' | 'lg' | 'md' | Presentation size. |
status | 'error' | 'warning' | — | Configure status. |
prefix | ReactNode | — | Leading content. |
suffix | ReactNode | — | Trailing content. |
formatter | ( value: number | string | null, info: { userTyping: boolean; input: string }, ) => string | — | Format displayed text without changing the canonical form value. |
parser | (text: string) => number | string | — | Parse displayed text back into a value. |
grouping | boolean | — | Use localized digit grouping. |
locale | string | — | Locale for language or numeric formatting. |
stringMode | true | — | Required. Use strings for exact values, steps and bounds. |
value | string | null | — | Controlled value. |
defaultValue | string | null | null | Initial value; uncontrolled fields support native form reset. |
onChange | (value: string | null) => void | — | Called when the value changes. |
min | string | — | Minimum allowed value. |
max | string | — | Maximum allowed value. |
step | string | '1' | Step; Slider uses only marked values when null. |