jsx_a11y/click-events-have-key-events Correctness
What it does
Enforce onClick is accompanied by at least one of the following: onKeyUp, onKeyDown, onKeyPress.
Why is this bad?
Coding for the keyboard is important for users with physical disabilities who cannot use a mouse, AT compatibility, and screenreader users. This does not apply for interactive or hidden elements.
Examples
Examples of incorrect code for this rule:
jsx
<div onClick={() => void 0} />;Examples of correct code for this rule:
jsx
<div onClick={() => void 0} onKeyDown={() => void 0} />;How to use
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"
}
}bash
oxlint --deny jsx-a11y/click-events-have-key-events --jsx-a11y-plugin