Material-ui: [TextField] type =缺少的最小,最大,步长Typescript类型数

创建于 2017-11-27  ·  8评论  ·  资料来源: mui-org/material-ui

  • [x]我搜索了此存储库的问题,并认为这不是重复的。

预期行为

<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 |

bug 🐛 TextField typescript

最有用的评论

这样行吗?

<TextField type="number" inputProps={{ min: "0", max: "10", step: "1" }} />

所有8条评论

这样行吗?

<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用于具有最小/最大/步长要求的数字字段时都必须扩展它。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

pola88 picture pola88  ·  3评论

newoga picture newoga  ·  3评论

mattmiddlesworth picture mattmiddlesworth  ·  3评论

anthony-dandrea picture anthony-dandrea  ·  3评论

ghost picture ghost  ·  3评论