0

我使用用 React + Typescript 编写的 Fabric 组件,当使用 Checkbox 组件时,我可以添加自定义属性等data-id- 这也写在文档中:https ://developer.microsoft.com/en-us/fabric#/components /复选框

有什么问题 ?我不知道如何通过将其传递给inputProps.

HTMLAttribute字段的 React 接口data需要string值。

从我所见,React 的接口HTMLAttribute是通用的,Checkbox 组件在那里传递了这个接口:https ://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/global.d.ts - 它们是空的。

有人知道如何在那里实现data-属性吗?

4

1 回答 1

1

在大多数接口扩展 React.ButtonAttributes 的情况下,我们过滤掉所有有效的按钮道具(包括 aria)并将它们通过管道输入。似乎这个组件从未更新以使用该方法,并且仍在使用我们放置所有这些的旧方法道具进入'inputProps'。

  <Checkbox 
  label="Standard checkbox"
  inputProps={{'data-foo': 'bar'}}
  ariaDescribedBy={'descriptionID'} />

https://codepen.io/micahgodbolt/pen/djNGQv

于 2018-07-20T17:29:48.213 回答