Skip to content

Commit 9174c4a

Browse files
authored
Merge pull request #523 from TrevorBurnham/no-static-element-interactions-bubble-docs
Rewrite bubbled events section in no-static-element-interactions docs
2 parents bf45563 + 0a1bf2f commit 9174c4a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

docs/rules/no-static-element-interactions.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In order to add interactivity such as a mouse or key event listener to a static
1212

1313
Indicate the element's role with the `role` attribute:
1414

15-
```
15+
```jsx
1616
<div
1717
onClick={onClickHandler}
1818
onKeyPress={onKeyPressHandler}
@@ -38,21 +38,23 @@ Common interactive roles include:
3838

3939
Note: Adding a role to your element does **not** add behavior. When a semantic HTML element like `<button>` is used, then it will also respond to Enter key presses when it has focus. The developer is responsible for providing the expected behavior of an element that the role suggests it would have: focusability and key press support.
4040

41-
### Case: This element is not a button, link, menuitem, etc. It is catching bubbled events from elements that it contains
41+
### Case: The event handler is only being used to capture bubbled events
4242

43-
If your element is catching bubbled click or key events from descendant elements, then the proper role for this element is `presentation`.
43+
If a static element has an event handler for the sole purpose of capturing events from its descendants, you can tell the linter to ignore it by setting `role="presentation"`:
4444

45-
```
45+
```jsx
4646
<div
47-
onClick="onClickHandler"
47+
onClick={this.handleButtonClick}
4848
role="presentation">
4949
<button>Save</button>
50+
<button>Cancel</button>
5051
</div>
5152
```
5253

53-
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.
54+
This `role` has no effect on static elements, but it clarifies your intent.
5455

5556
### References
57+
5658
1. [WAI-ARIA `role` attribute](https://www.w3.org/TR/wai-aria-1.1/#usage_intro)
5759
1. [WAI-ARIA Authoring Practices Guide - Design Patterns and Widgets](https://www.w3.org/TR/wai-aria-practices-1.1/#aria_ex)
5860
1. [Fundamental Keyboard Navigation Conventions](https://www.w3.org/TR/wai-aria-practices-1.1/#kbd_generalnav)
@@ -81,13 +83,15 @@ You may configure which handler props should be taken into account when applying
8183
Adjust the list of handler prop names in the handlers array to increase or decrease the coverage surface of this rule in your codebase.
8284

8385
### Succeed
86+
8487
```jsx
8588
<button onClick={() => {}} className="foo" />
8689
<div className="foo" onClick={() => {}} role="button" />
8790
<input type="text" onClick={() => {}} />
8891
```
8992

9093
### Fail
94+
9195
```jsx
9296
<div onClick={() => {}} />
9397
```

0 commit comments

Comments
 (0)