Skip to content

Commit 18c9b71

Browse files
committed
Remove onclick-has-role test
1 parent 4cf8340 commit 18c9b71

File tree

5 files changed

+15
-180
lines changed

5 files changed

+15
-180
lines changed

__tests__/src/rules/onclick-has-role-test.js

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
# no-noninteractive-element-handlers
22

3-
Write a useful explanation here!
3+
Enforce visible, non-interactive elements with click handlers use role attribute. Visible means that it is not hidden from a screen reader. Examples of non-interactive elements are `div`, `section`, and `a` elements without a href prop. The purpose of the role attribute is to identify to screenreaders the exact function of an element. This rule will only test low-level DOM components, as we can not deterministically map wrapper JSX components to their correct DOM element.
4+
5+
In cases where a non-interactive element has a handler, but does not map to an interactive role such as `button` or `link` -- for example a `div` container that catches bubbled click events -- `onclick-has-role` may be satisfied by providing a role value of `presentation`. This indicates that the element has no semantic value. A role like `button` or `link` should only be applied when the non-interactive element truly represents such a UI element.
46

57
#### References
6-
1.
8+
1. [MDN](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role#Keyboard_and_focus)
79

810
## Rule details
911

1012
This rule takes no arguments.
1113

1214
### Succeed
1315
```jsx
14-
<div />
16+
<div onClick={() => void 0} role="button" />
17+
<div onClick={() => void 0} role="presentation" />
18+
<input type="text" onClick={() => void 0} /> // Interactive element does not require role.
19+
<a tabIndex="0" onClick={() => void 0} /> // tabIndex makes this interactive.
20+
<button onClick={() => void 0} className="foo" /> // button is interactive.
21+
<div onClick={() => void 0} role="button" aria-hidden /> // This is hidden from screenreader.
22+
<Input onClick={() => void 0} type="hidden" /> // This is a higher-level DOM component
1523
```
1624

1725
### Fail
1826
```jsx
19-
27+
<div onClick={() => void 0} />
28+
<div onClick={() => void 0} {...props} />
29+
<div onClick={() => void 0} aria-hidden={false} />
30+
<a onClick={() => void 0} />
2031
```

docs/rules/onclick-has-role.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ module.exports = {
2929
'no-redundant-roles': require('./rules/no-redundant-roles'),
3030
'no-static-element-interactions': require('./rules/no-static-element-interactions'),
3131
'onclick-has-focus': require('./rules/onclick-has-focus'),
32-
'onclick-has-role': require('./rules/onclick-has-role'),
3332
'role-has-required-aria-props': require('./rules/role-has-required-aria-props'),
3433
'role-supports-aria-props': require('./rules/role-supports-aria-props'),
3534
scope: require('./rules/scope'),
@@ -69,7 +68,6 @@ module.exports = {
6968
'jsx-a11y/no-redundant-roles': 'error',
7069
'jsx-a11y/no-static-element-interactions': 'warn',
7170
'jsx-a11y/onclick-has-focus': 'error',
72-
'jsx-a11y/onclick-has-role': 'error',
7371
'jsx-a11y/role-has-required-aria-props': 'error',
7472
'jsx-a11y/role-supports-aria-props': 'error',
7573
'jsx-a11y/scope': 'error',

src/rules/onclick-has-role.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)