我有以下代码:
Enabled = (id) => {
let removal = null;
if (!this.props.disabled) {
removal = (
<span
className="chipRemove"
onClick={() => this.onDelete(id)}
>
x
</span>)
;
}
return removal;
}
它运作良好,但 linter 给了我:
jsx-a11y/no-static-element-interactions
我该如何解决这个错误(根据jsx-a11y
)?
来自文档:
强制非交互式 DOM 元素没有交互式处理程序。
静态元素,例如<div> and <span>
不该有
鼠标/键盘事件监听器。相反,使用更语义化的东西,
例如按钮或链接。
有效的交互元素是:
<a> elements with href or tabIndex props
<button> elements
<input> elements that are not hidden
<select> and <option> elements
<textarea> elements
<area> elements
参考:https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)