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
+43-16Lines changed: 43 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,24 +21,25 @@ Indicate the element's role with the `role` attribute:
21
21
onClick={onClickHandler}
22
22
onKeyPress={onKeyPressHandler}
23
23
role="button"
24
-
tabindex="0">
24
+
tabindex="0"
25
+
>
25
26
Save
26
27
</div>
27
28
```
28
29
29
30
Common interactive roles include:
30
31
31
-
1.`button`
32
-
1.`link`
33
-
1.`checkbox`
34
-
1.`menuitem`
35
-
1.`menuitemcheckbox`
36
-
1.`menuitemradio`
37
-
1.`option`
38
-
1.`radio`
39
-
1.`searchbox`
40
-
1.`switch`
41
-
1.`textbox`
32
+
1.`button`
33
+
1.`link`
34
+
1.`checkbox`
35
+
1.`menuitem`
36
+
1.`menuitemcheckbox`
37
+
1.`menuitemradio`
38
+
1.`option`
39
+
1.`radio`
40
+
1.`searchbox`
41
+
1.`switch`
42
+
1.`textbox`
42
43
43
44
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.
44
45
@@ -47,12 +48,16 @@ Note: Adding a role to your element does **not** add behavior. When a semantic H
47
48
If your element is catching bubbled click or key events from descendant elements, there are no appropriate roles for your element: you will have to deactivate the rule. Consider explaining the reason for disabling the rule as well.
48
49
49
50
```jsx
50
-
{/* The <div> element has a child <button> element that allows keyboard interaction */}
Do not use the role `presentation` on the element: it removes the element's semantics, and may also remove its children's semantics, creating big issues with assistive technology.
@@ -74,11 +79,23 @@ You may configure which handler props should be taken into account when applying
74
79
'onKeyUp',
75
80
],
76
81
allowExpressionValues:true,
82
+
attributes: [
83
+
{
84
+
components: ['a', 'Link'],
85
+
attributes: {
86
+
href: ['to', 'href'],
87
+
},
88
+
},
89
+
],
77
90
},
78
91
],
79
92
```
80
93
81
-
Adjust the list of handler prop names in the handlers array to increase or decrease the coverage surface of this rule in your codebase.
94
+
### `handlers`
95
+
96
+
Adjust the list of handler prop names in the `handlers` array to increase or decrease the coverage surface of this rule in your codebase.
97
+
98
+
### `allowExpressionValues`
82
99
83
100
The `allowExpressionValues` option determines whether the `role` attribute is allowed to be assigned using an expression. For example, the following would pass in recommended mode if `allowExpressionValues` is set to be `true`:
84
101
@@ -88,6 +105,16 @@ The `allowExpressionValues` option determines whether the `role` attribute is al
The `attributes` array allows to set custom attributes for a given list of components. This is useful in cases where you are utilizing libraries that may have different prop names mapped to a native attribute (e.g., `to` being used for `href`)
111
+
112
+
```jsx
113
+
// these will be valid given the `attributes` option above
0 commit comments