Skip to content

Commit 122d824

Browse files
authored
Merge pull request #211 from jessebeach/update-docs
Update no-static-element-interactions docs; various other improvements
2 parents 3d4488a + 0467888 commit 122d824

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ You can also enable all the recommended rules at once. Add `plugin:jsx-a11y/reco
113113
- [no-access-key](docs/rules/no-access-key.md): Enforce that the `accessKey` prop is not used on any element to avoid complications with keyboard commands used by a screenreader.
114114
- [no-autofocus](docs/rules/no-autofocus.md): Enforce autoFocus prop is not used.
115115
- [no-distracting-elements](docs/rules/no-distracting-elements.md): Enforce distracting elements are not used.
116+
- [no-interactive-element-to-noninteractive-role](docs/rules/no-interactive-element-to-noninteractive-role.md): Interactive elements should not be assigned non-interactive roles.
117+
- [no-noninteractive-element-interactions](docs/rules/no-noninteractive-element-interactions.md): Non-interactive elements should not be assigned mouse or keyboard event listeners.
118+
- [no-noninteractive-element-to-interactive-role](docs/rules/no-noninteractive-element-to-interactive-role.md): Non-interactive elements should not be assigned interactive roles.
116119
- [no-onchange](docs/rules/no-onchange.md): Enforce usage of `onBlur` over `onChange` on select menus for accessibility.
117120
- [no-redundant-roles](docs/rules/no-redundant-roles.md): Enforce explicit role property is not the same as implicit/default role property on element.
118121
- [no-static-element-interactions](docs/rules/no-static-element-interactions.md): Enforce that non-interactive, visible elements (such as `<div>`) that have click handlers use the role attribute.

__tests__/src/rules/no-noninteractive-element-interactions-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const expectedError = {
2626
type: 'JSXOpeningElement',
2727
};
2828

29-
ruleTester.run('no-noninteractive-element-handlers', rule, {
29+
ruleTester.run('no-noninteractive-element-interactions', rule, {
3030
valid: [
3131
{ code: '<TestComponent onClick={doFoo} />' },
3232
{ code: '<Button onClick={doFoo} />' },

docs/rules/no-noninteractive-element-handlers.md renamed to docs/rules/no-noninteractive-element-interactions.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ Move the event handler function to an inner element like `<div>` and give that e
4242

4343
Marking an element with the role `presentation` indicates to assistive technology that this element should be ignored; it exists to support the web application and is not meant for humans to interact with directly.
4444

45+
### Case: This is a heading that expands/collapses content on the package
46+
47+
Headers often double as expand/collapse controls for the content they headline. An accordion component is a common example of this pattern. Rather than assign the interaction handling code to the heading itself, put a button inside the heading instead. This pattern retains the role of the heading and the role of the button.
48+
49+
```jsx
50+
<h3>
51+
<button onClick={this._expandSection}>News</button>
52+
</h3>
53+
<ul id="articles-list">
54+
<li>...</li>
55+
</ul>
56+
```
57+
4558
### References
4659

4760
1. [WAI-ARIA roles](https://www.w3.org/TR/wai-aria-1.1/#usage_intro)

0 commit comments

Comments
 (0)