我想向材质UI按钮添加辅助功能。
我希望按如下方式使用此自定义按钮:
import Button from '@material-ui/core/Button';
function AccessibleButton(props) {
const { accessKey, ariaLabel, isDisabled, label, onClick, tabIndex, variant, size} = props;
return (
<Button
accesskey={accessKey}
aria-label={ariaLabel}
disabled={isDisabled}
className={componentCls}
onClick={onClick}
tabindex={tabIndex}
variant={variant}
size={size}
>
{label}
</Button>
);
};
Aria标签可用于输入,但似乎不适用于按钮。如何将其他道具(assessKey,ariaLabel)传递到“材质UI”按钮中。我该怎么做呢?
这应该起作用,因为我们的大多数组件都转发了多余的道具。在相应的api页面(此处为https://material-ui.com/api/button/)上,您会找到带有明显道具的表格。在此下方是一个注释,告诉您多余的道具会发生什么。
导航有点麻烦(我们正在努力),但最后您会看到多余的道具被转发到了原生元素。因此<Button aria-label="ariaLabel" />
将渲染一个<button aria-label="ariaLabel" />
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句