【发布时间】:2019-07-11 04:47:26
【问题描述】:
库styled-components 使您能够创建自定义样式的组件,例如:
const Button = styled.div`
display: inline-block;
border-radius: 3px;
padding: 0.5rem 0;
margin: 0.5rem 1rem;
width: 11rem;
background: transparent;
color: white;
border: 2px solid white;
`;
function App(props) {
return (<Button onClick={() => console.log("clicked!")}>Styled</Button>);
}
以下按钮是可点击的,但由<div /> 元素组成,因此eslint-plugin-jsx-a11y 通常需要tabIndex、role 等属性。
问题是因为从styled.divES-Lint 创建的组件看不到它。有解决这个问题的插件或解决方案吗?
【问题讨论】:
-
您可以使用其他方法测试 a11y,例如使用
axe-core进行单元测试。它的规则比 jsx-a11y 多很多
标签: reactjs accessibility eslint styled-components