<TextField type="number" min="0" max="10" step="1" />
应该使用Typescript编译
收到以下打字稿错误的最小值,最大值和步骤类似: [ts] Property 'min' does not exist on type 'IntrinsicAttributes & TextFieldProps & { children?: ReactNode; }'.
| 技术| 版本|
| -------------- | --------- |
| Material-UI | 1.0.0-beta.21 |
| 反应| 16.0.0 |
| 打字稿| 2.6.1 |
这样行吗?
<TextField type="number" inputProps={{ min: "0", max: "10", step: "1" }} />
是的,行得通。 inputProps
接受其中包含任何对象的对象,因此我通过这种方式有效地退出了类型系统。
是的,行得通。
inputProps
接受其中包含任何对象的对象,因此我通过这种方式有效地退出了类型系统。
好点,我已经打开#9321来修复inputProps
。
inputProps
旨在允许InputComponent
。 这允许与外部组件进行开放集成,不幸的是我们可能不知道或没有类型。
例:
import * as MaskedInput from 'react-text-mask'
<TextField
InputProps={{
inputComponent: MaskedInput,
}}
inputProps={{
guide: false,
mask,
placeholderChar: '\u2000',
}}
type="tel"
value={value}
/>
因此,在相同情况下(避免@pelotom)避免强类型inputProps
的另一种方法是
import { InputProps as MuiInputProps } from 'material-ui/Input'
<TextField
InputProps={{
inputComponent: (inputProps: MuiInputProps) => (
<MaskedInput {...inputProps} guide={false} mask={mask} placeholderChar="\u2000" />
),
}}
type="tel"
value={value}
/>
@pelotom正在提交新的提案/问题以重新访问此API。
@rosskevin
未定义MaskedInput,
掩码未定义
:(
这似乎是一个过于复杂的解决方法
最好在TextField级别上定义它们,以便执行验证而无需到处都是一堆重复的逻辑。 我不希望每次将TextField用于具有最小/最大/步长要求的数字字段时都必须扩展它。
最有用的评论
这样行吗?