jsx-a11y/click-events-have-key-events Correctness
它的作用
强制 onClick 至少伴随以下之一:onKeyUp、onKeyDown、onKeyPress。
为什么这不好?
为键盘进行编码对无法使用鼠标的身体残障用户、AT 兼容性以及屏幕阅读器用户都很重要。 这不适用于交互元素或隐藏元素。
示例
此规则的错误代码示例:
jsx
<div onClick={() => void 0} />此规则的正确代码示例:
jsx
<div onClick={() => void 0} onKeyDown={() => void 0} />如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["jsx-a11y"],
"rules": {
"jsx-a11y/click-events-have-key-events": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["jsx-a11y"],
rules: {
"jsx-a11y/click-events-have-key-events": "error",
},
});bash
oxlint --deny jsx-a11y/click-events-have-key-events --jsx-a11y-plugin版本
此规则在 v0.2.1 中添加。
