Skip to content

Commit 1aa7815

Browse files
committed
Use propValue for anything else
1 parent 8abef65 commit 1aa7815

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/utils/get-role.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {getProp, getLiteralPropValue} = require('jsx-ast-utils')
1+
const {getProp, getPropValue, getLiteralPropValue} = require('jsx-ast-utils')
22
const {elementRoles} = require('aria-query')
33
const {getElementType} = require('./get-element-type')
44
const ObjectMap = require('./object-map')
@@ -80,7 +80,7 @@ function getRole(context, node) {
8080
continue
8181
}
8282

83-
const value = getLiteralPropValue(propOnNode)
83+
const value = getPropValue(propOnNode)
8484
if (value || (value === '' && prop === 'alt')) {
8585
if (
8686
prop === 'href' ||

tests/a11y-role-supports-aria-props.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ ruleTester.run('a11y-role-supports-aria-props', rule, {
3535
{code: '<div role />'},
3636
{code: '<div role="presentation" {...props} />'},
3737
{code: '<Foo.Bar baz={true} />'},
38+
{code: '<Foo as="a" href={url} aria-label={`Issue #${title}`} />'},
3839
{code: '<Link href="#" aria-checked />'},
3940
// Don't try to evaluate expression
4041
{code: '<Box aria-labelledby="some-id" role={role} />'},
41-
{code: '<Box aria-labelledby="some-id"as={isNavigationOpen ? "div" : "nav"} />'},
42-
42+
{code: '<Box aria-labelledby="some-id" as={isNavigationOpen ? "div" : "nav"} />'},
4343
// IMPLICIT ROLE TESTS
4444
// A TESTS - implicit role is `link`
4545
{code: '<a href="#" aria-expanded />'},

tests/utils/get-role.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ describe('getRole', function () {
4646
expect(getRole({}, node)).to.equal('link')
4747
})
4848

49+
it('returns link role for <Foo> with polymorphic prop set to "a" and href', function () {
50+
const node = mockJSXOpeningElement('Foo', [
51+
mockJSXAttribute('as', 'a'),
52+
[mockJSXConditionalAttribute('href', 'getUrl', '#', 'https://github.com/')],
53+
])
54+
expect(getRole({}, node)).to.equal('link')
55+
})
56+
4957
it('returns region role for <section> with aria-label', function () {
5058
const node = mockJSXOpeningElement('section', [mockJSXAttribute('aria-label', 'something')])
5159
expect(getRole({}, node)).to.equal('region')

0 commit comments

Comments
 (0)