Skip to content

Commit 26fa49a

Browse files
authored
fix(commons): Allow any node in aria.getRole (#1258)
Simple change I need for the accName update in #1163. ## Reviewer checks **Required fields, to be filled out by PR reviewer(s)** - [x] Follows the commit message policy, appropriate for next version - [x] Has documentation updated, a DU ticket, or requires no documentation change - [x] Includes new tests, or was unnecessary - [x] Code is reviewed for security by: dylanb
1 parent 439b826 commit 26fa49a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/commons/aria/get-role.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ aria.getRole = function getRole(
1818
node,
1919
{ noImplicit, fallback, abstracts, dpub } = {}
2020
) {
21+
node = node.actualNode || node;
22+
if (node.nodeType !== 1) {
23+
return null;
24+
}
2125
const roleAttr = (node.getAttribute('role') || '').trim().toLowerCase();
2226
const roleList = fallback ? axe.utils.tokenList(roleAttr) : [roleAttr];
2327

test/commons/aria/get-role.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ describe('aria.getRole', function() {
5353
assert.isNull(aria.getRole(node));
5454
});
5555

56+
it('accepts virtualNode objects', function() {
57+
var node = document.createElement('div');
58+
node.setAttribute('role', 'button');
59+
assert.equal(aria.getRole({ actualNode: node }), 'button');
60+
});
61+
62+
it('returns null if the node is not an element', function() {
63+
var node = document.createTextNode('foo bar baz');
64+
assert.isNull(aria.getRole(node));
65+
});
66+
5667
describe('noImplicit', function() {
5768
it('returns the implicit role by default', function() {
5869
var node = document.createElement('li');

0 commit comments

Comments
 (0)