【问题标题】:Material-UI: How to apply input attributes using TextFieldMaterial-UI:如何使用 TextField 应用输入属性
【发布时间】:2019-02-12 00:35:41
【问题描述】:

我有几个输入字段 (TextField),我想为可访问性添加一些 aria-* 属性。

我正在尝试这种方式:

const props = {
  InputProps: {
    'aria-label': 'myAriaLabel'
  }
}

// ...

<TextField {...props}></TextField>

但 Material-UI 最终将属性应用于生成的包装 div。比如:

<div aria-label="myAriaLabel"><input /></div>

如何将此属性正确放置到input 元素中?

【问题讨论】:

    标签: reactjs material-ui


    【解决方案1】:

    你只需要一个小写的 i。

    InputProps 用于Input 组件。 inputProps 用于 input 元素。

    https://material-ui.com/api/text-field/#props

    【讨论】:

    • 非常有帮助。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多