diff --git a/lib/utils/get-role.js b/lib/utils/get-role.js index 8fea9178..54654ee8 100644 --- a/lib/utils/get-role.js +++ b/lib/utils/get-role.js @@ -46,6 +46,9 @@ function getRole(context, node) { const explicitRole = getLiteralPropValue(getProp(node.attributes, 'role')) if (explicitRole) { return explicitRole + } else if (getProp(node.attributes, 'role')) { + // If role is set to anything other than a literal prop + return undefined } // Assemble a key for looking-up the element’s role in the `elementRolesMap` diff --git a/tests/a11y-role-supports-aria-props.js b/tests/a11y-role-supports-aria-props.js index a367e454..424c363a 100644 --- a/tests/a11y-role-supports-aria-props.js +++ b/tests/a11y-role-supports-aria-props.js @@ -29,6 +29,18 @@ function getErrorMessage(attribute, role) { ruleTester.run('a11y-role-supports-aria-props', rule, { valid: [ + { + code: ` +
+ {children} +
`, + }, {code: ''}, {code: '
'}, {code: '
'}, diff --git a/tests/utils/get-role.js b/tests/utils/get-role.js index c8d2aa5b..86c3bdc8 100644 --- a/tests/utils/get-role.js +++ b/tests/utils/get-role.js @@ -13,8 +13,8 @@ describe('getRole', function () { }) it('returns undefined when role is set to non-literal expression', function () { - // - const node = mockJSXOpeningElement('Box', [ + //
+ const node = mockJSXOpeningElement('div', [ mockJSXConditionalAttribute('role', 'isNavigationOpen', 'generic', 'navigation'), ]) expect(getRole({}, node)).to.equal(undefined)