数字输入框
数字输入组件为用户提供一个用于整数值的字段,以及用于增加或减少值的按钮。
useNumberInput API
导入
import { unstable_useNumberInput as useNumberInput } from '@mui/base/unstable_useNumberInput';
// or
import { unstable_useNumberInput as useNumberInput } from '@mui/base';
通过阅读这篇关于最小化捆绑包大小的指南,了解两者之间的区别。
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
componentName | string | 'useNumberInput' | 使用 useNumberInput 的组件名称。用于调试目的。 |
defaultValue | number | null | - | 默认值。当组件不受控制时使用。 |
disabled | boolean | - | 如果为 |
error | boolean | - | 如果为 |
inputId | string | - | input 元素的 |
inputRef | React.Ref<HTMLInputElement> | - | input 元素的 ref。 |
max | number | - | 最大值。 |
min | number | - | 最小值。 |
onBlur | (event?: React.FocusEvent<HTMLInputElement>) => void | - | |
onChange | (event: React.FocusEvent<HTMLInputElement> | React.PointerEvent | React.KeyboardEvent, value: number | null) => void | - | 当 |
onClick | React.MouseEventHandler | - | |
onFocus | React.FocusEventHandler | - | |
onInputChange | React.ChangeEventHandler<HTMLInputElement> | - | 在每次按键后,在应用限制之前,当 |
readOnly | boolean | false | 如果为 |
required | boolean | - | 如果为 |
shiftMultiplier | number | - | 如果在增加或减少值时按住 shift 键,则应用于 |
step | number | - | 每次增加或减少时值变化的量。 |
value | number | null | null | 当前值。当组件受控时使用。 |
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
disabled | boolean | false | 如果为 |
error | boolean | false | 如果为 |
focused | boolean | false | 如果为 |
formControlContext | FormControlState | undefined | - | 来自 |
getDecrementButtonProps | <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseNumberInputDecrementButtonSlotProps<ExternalProps> | - | 用于减量按钮 slot 属性的解析器。 |
getIncrementButtonProps | <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseNumberInputIncrementButtonSlotProps<ExternalProps> | - | 用于增量按钮 slot 属性的解析器。 |
getInputProps | <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseNumberInputInputSlotProps<ExternalProps> | - | 用于 input slot 属性的解析器。 |
getRootProps | <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseNumberInputRootSlotProps<ExternalProps> | - | 用于 root slot 属性的解析器。 |
inputValue | string | - |
|
isDecrementDisabled | boolean | false | 如果为 |
isIncrementDisabled | boolean | false | 如果为 |
required | boolean | false | 如果为 |
value | number | null | - |
|