InputNumber
Numeric-only input with range clamping, step and precision control, stepped via buttons or arrow keys.
Basic usage
The first row is the controlled usage (stepping via buttons or arrow keys; manual input commits on blur or Enter); the second row clamps the value into the min / max range; the third row fixes decimals with precision, snaps input onto the step grid with stepStrictly (multiples of the step), and disables with disabled; the fourth row shows the three sizes and controls={false} to hide the control buttons.
import { useState } from 'react'
import { LhInputNumber } from '@lh-ui/react'
export default function Demo() {
const [value, setValue] = useState<number | null>(1)
return <LhInputNumber value={value} onChange={setValue} min={1} max={10} />
}
InputNumber Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| value | Controlled value (null means empty) | number | null | — | — |
| defaultValue | Uncontrolled default value | number | null | — | null |
| min | Minimum value | number | — | -Infinity |
| max | Maximum value | number | — | Infinity |
| step | Step (its absolute value is used) | number | — | 1 |
| stepStrictly | Snap input onto the step grid based on min | boolean | — | false |
| precision | Numeric precision (decimal places) | number | — | — |
| disabled | Whether to disable | boolean | — | false |
| size | Size | 'large' | 'medium' | 'small' | — | 'medium' |
| controls | Whether to show the increment / decrement buttons | boolean | — | true |
| placeholder | Placeholder | string | — | '' |
| name | Native name attribute | string | — | — |
| sx | Shorthand layout props | SxProps | — | — |
InputNumber events
| Event | Description | Callback signature | Vue equivalent |
|---|---|---|---|
| onChange | Value change (fired by both stepping and committing; null when committed as empty) | (value: number | null) => void | @update:modelValue / @change |
The input carries role="spinbutton" with the aria-valuemin / aria-valuemax / aria-valuenow value semantics. Press ↑ / ↓ while focused to step by step; manual input commits on blur or Enter — an empty string clears to null, invalid numbers fall back to the previous value, and valid values go through precision rounding and min / max clamping, then snap onto the step grid (rounded) when stepStrictly is on.
ref
forwardRef<HTMLInputElement> — the focusable native input element.
Styles
import '@lh-ui/react/style/input-number'