Skip to content

Commit 0c19f02

Browse files
V2dhaljharb
authored andcommitted
[Docs] no-noninteractive-tabindex, no-static-element-interactions: document allowExpressionValues
1 parent e7d405d commit 0c19f02

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

docs/rules/no-noninteractive-tabindex.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ If you know that a particular element will be scrollable, you might want to add
5050

5151
```jsx
5252
// eslint-disable-next-line no-noninteractive-tabindex
53-
<pre tabIndex="0">
53+
<pre tabIndex="0">
5454
<code>{someLongCode}</code>
5555
</pre>
5656
```
@@ -65,9 +65,16 @@ The recommended options for this rule allow `tabIndex` on elements with the noni
6565
{
6666
tags: [],
6767
roles: ['tabpanel'],
68+
allowExpressionValues: true,
6869
},
6970
]
7071
```
72+
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`:
73+
```jsx
74+
<div role={ROLE_BUTTON} onClick={() => {}} tabIndex="0" />;
75+
// In case of a conditional expression, there should be literals on both sides of ternary operator
76+
<div role={isButton ? "button" : "link"} onClick={() => {}} tabIndex="0" />;
77+
```
7178

7279
### Succeed
7380
```jsx

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Do not use the role `presentation` on the element: it removes the element's sema
5555

5656
## Rule details
5757

58-
You may configure which handler props should be taken into account when applying this rule. The recommended configuration includes the following 6 handlers.
58+
You may configure which handler props should be taken into account when applying this rule. The recommended configuration includes the following 6 handlers and the `allowExpressionValues` option.
5959

6060
```javascript
6161
'jsx-a11y/no-static-element-interactions': [
@@ -69,12 +69,20 @@ You may configure which handler props should be taken into account when applying
6969
'onKeyDown',
7070
'onKeyUp',
7171
],
72+
allowExpressionValues: true,
7273
},
7374
],
7475
```
7576

7677
Adjust the list of handler prop names in the handlers array to increase or decrease the coverage surface of this rule in your codebase.
7778

79+
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`:
80+
```jsx
81+
<div role={ROLE_BUTTON} onClick={() => {}} />;
82+
// In case of a conditional expression, there should be literals on both sides of ternary operator
83+
<div role={isButton ? "button" : "link"} onClick={() => {}} />;
84+
```
85+
7886
### Succeed
7987

8088
```jsx

0 commit comments

Comments
 (0)