src/content/docs/linter/rules/use-key-with-click-events.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JSX and TSX" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/a11y/useKeyWithClickEvents`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`jsx-a11y/click-events-have-key-events`](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/click-events-have-key-events.md){
"linter": {
"rules": {
"a11y": {
"useKeyWithClickEvents": "error"
}
}
}
}
Enforce onClick is accompanied by at least one of the following: onKeyUp, onKeyDown, onKeyPress.
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.
<div onClick={() => {}} />
<div onClick={() => {}} onKeyDown={handleKeyDown} />
<div onClick={() => {}} onKeyUp={handleKeyUp} />
<div onClick={() => {}} onKeyPress={handleKeyPress} />
// this rule doesn't apply to user created component
<MyComponent onClick={() => {}} />
<button onClick={() => console.log("test")}>Submit</button>