Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7036141

Browse filesBrowse files
committed
Add logic to check for presence of attribute
1 parent 8abef65 commit 7036141
Copy full SHA for 7036141

File tree

Expand file treeCollapse file tree

3 files changed

+25
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-4
lines changed

‎lib/utils/get-role.js

Copy file name to clipboardExpand all lines: lib/utils/get-role.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function getRole(context, node) {
8181
}
8282

8383
const value = getLiteralPropValue(propOnNode)
84-
if (value || (value === '' && prop === 'alt')) {
84+
if (propOnNode) {
8585
if (
8686
prop === 'href' ||
8787
prop === 'aria-labelledby' ||
@@ -90,7 +90,7 @@ function getRole(context, node) {
9090
(prop === 'alt' && value !== '')
9191
) {
9292
key.attributes.push({name: prop, constraints: ['set']})
93-
} else {
93+
} else if (value || (value === '' && prop === 'alt')) {
9494
key.attributes.push({name: prop, value})
9595
}
9696
}

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

Copy file name to clipboardExpand all lines: tests/a11y-role-supports-aria-props.js
+2-2Lines 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

Copy file name to clipboardExpand all lines: tests/utils/get-role.js
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ 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 conditional 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+
57+
it('returns link role for <Foo> with polymorphic prop set to "a" and literal href', function () {
58+
const node = mockJSXOpeningElement('Foo', [
59+
mockJSXAttribute('as', 'a'),
60+
mockJSXAttribute('href', 'https://github.com/'),
61+
])
62+
expect(getRole({}, node)).to.equal('link')
63+
})
64+
65+
it('returns generic role for <Foo> with polymorphic prop set to "a" and no href', function () {
66+
const node = mockJSXOpeningElement('Foo', [mockJSXAttribute('as', 'a')])
67+
expect(getRole({}, node)).to.equal('generic')
68+
})
69+
4970
it('returns region role for <section> with aria-label', function () {
5071
const node = mockJSXOpeningElement('section', [mockJSXAttribute('aria-label', 'something')])
5172
expect(getRole({}, node)).to.equal('region')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.