Skip to content

Commit 19e4ba9

Browse files
committed
Fix bug in get-role
1 parent 9159923 commit 19e4ba9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/utils/get-role.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ function getRole(context, node) {
4646
const explicitRole = getLiteralPropValue(getProp(node.attributes, 'role'))
4747
if (explicitRole) {
4848
return explicitRole
49+
} else if (getProp(node.attributes, 'role')) { // If role is set to anything other than a literal prop
50+
return undefined
4951
}
5052

5153
// Assemble a key for looking-up the element’s role in the `elementRolesMap`

tests/utils/get-role.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ describe('getRole', function () {
1313
})
1414

1515
it('returns undefined when role is set to non-literal expression', function () {
16-
// <Box role={isNavigationOpen ? 'generic' : 'navigation'} />
17-
const node = mockJSXOpeningElement('Box', [
16+
// <div role={isNavigationOpen ? 'generic' : 'navigation'} />
17+
const node = mockJSXOpeningElement('div', [
1818
mockJSXConditionalAttribute('role', 'isNavigationOpen', 'generic', 'navigation'),
1919
])
2020
expect(getRole({}, node)).to.equal(undefined)

0 commit comments

Comments
 (0)