Skip to content

Commit 03441cd

Browse files
authored
Merge pull request #542 from TrevorBurnham/role-supports-aria-props-null
Allow role-incompatible props to be null/undefined
2 parents 8b1a550 + f074ef8 commit 03441cd

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

__tests__/src/rules/role-supports-aria-props-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ ruleTester.run('role-supports-aria-props', rule, {
379379
{ code: '<input type="url" aria-disabled />' },
380380
{ code: '<input aria-disabled />' },
381381

382+
// Allow null/undefined values regardless of role
383+
{ code: '<h2 role="presentation" aria-level={null} />' },
384+
{ code: '<h2 role="presentation" aria-level={undefined} />' },
385+
382386
// OTHER TESTS
383387
{ code: '<aside aria-expanded />' },
384388
{ code: '<article aria-expanded />' },

src/rules/role-supports-aria-props.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import {
1616
getProp,
1717
getLiteralPropValue,
18+
getPropValue,
1819
elementType,
1920
propName,
2021
} from 'jsx-ast-utils';
@@ -67,9 +68,11 @@ module.exports = {
6768
.filter(attribute => propertySet.indexOf(attribute) === -1);
6869

6970
node.attributes.forEach((prop) => {
70-
if (prop.type === 'JSXSpreadAttribute') {
71-
return;
72-
}
71+
// Ignore the attribute if its value is null or undefined.
72+
if (getPropValue(prop) == null) return;
73+
74+
// Ignore the attribute if it's a spread.
75+
if (prop.type === 'JSXSpreadAttribute') return;
7376

7477
const name = propName(prop);
7578
if (invalidAriaPropsForRole.indexOf(name) > -1) {

0 commit comments

Comments
 (0)