You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/no-static-element-interactions.md
+10-6Lines changed: 10 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ In order to add interactivity such as a mouse or key event listener to a static
12
12
13
13
Indicate the element's role with the `role` attribute:
14
14
15
-
```
15
+
```jsx
16
16
<div
17
17
onClick={onClickHandler}
18
18
onKeyPress={onKeyPressHandler}
@@ -38,21 +38,23 @@ Common interactive roles include:
38
38
39
39
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.
40
40
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
42
42
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"`:
44
44
45
-
```
45
+
```jsx
46
46
<div
47
-
onClick="onClickHandler"
47
+
onClick={this.handleButtonClick}
48
48
role="presentation">
49
49
<button>Save</button>
50
+
<button>Cancel</button>
50
51
</div>
51
52
```
52
53
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.
0 commit comments