Skip to content

Commit

Permalink
fix(commons): Allow any node in aria.getRole (#1258)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
WilcoFiers authored Nov 26, 2018
1 parent 439b826 commit 26fa49a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/commons/aria/get-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ aria.getRole = function getRole(
node,
{ noImplicit, fallback, abstracts, dpub } = {}
) {
node = node.actualNode || node;
if (node.nodeType !== 1) {
return null;
}
const roleAttr = (node.getAttribute('role') || '').trim().toLowerCase();
const roleList = fallback ? axe.utils.tokenList(roleAttr) : [roleAttr];

Expand Down
11 changes: 11 additions & 0 deletions test/commons/aria/get-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ describe('aria.getRole', function() {
assert.isNull(aria.getRole(node));
});

it('accepts virtualNode objects', function() {
var node = document.createElement('div');
node.setAttribute('role', 'button');
assert.equal(aria.getRole({ actualNode: node }), 'button');
});

it('returns null if the node is not an element', function() {
var node = document.createTextNode('foo bar baz');
assert.isNull(aria.getRole(node));
});

describe('noImplicit', function() {
it('returns the implicit role by default', function() {
var node = document.createElement('li');
Expand Down

0 comments on commit 26fa49a

Please sign in to comment.