-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Ignore abstracts in determining element roles
- Loading branch information
1 parent
3a8729b
commit 1af6088
Showing
10 changed files
with
157 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
return !axe.commons.aria.isValidRole(node.getAttribute('role')); | ||
return !axe.commons.aria.isValidRole(node.getAttribute('role'), { | ||
allowAbstract: true | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
const parent = axe.commons.dom.getComposedParent(node); | ||
if (!parent) { | ||
return false; | ||
// Can only happen with detached DOM nodes and roots: | ||
return undefined; | ||
} | ||
|
||
const ALLOWED_TAGS = ['UL', 'OL']; | ||
const parentTagName = parent.nodeName.toUpperCase(); | ||
|
||
const parentRole = (parent.getAttribute('role') || '').toLowerCase(); | ||
if (parentRole && !axe.commons.aria.isValidRole(parentRole)) { | ||
|
||
if (parentRole === 'list') { | ||
return true; | ||
} | ||
|
||
if (parentRole && axe.commons.aria.isValidRole(parentRole)) { | ||
return false; | ||
} | ||
|
||
const isListRole = parentRole === 'list'; | ||
return ( | ||
(ALLOWED_TAGS.includes(parentTagName) && (!parentRole || isListRole)) || | ||
isListRole | ||
); | ||
return ['UL', 'OL'].includes(parentTagName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,91 @@ | ||
describe('dlitem', function () { | ||
describe('dlitem', function() { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var checkSetup = axe.testUtils.checkSetup; | ||
var shadowSupport = axe.testUtils.shadowSupport; | ||
|
||
afterEach(function () { | ||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('should pass if the dlitem has a parent <dl>', function () { | ||
it('should pass if the dlitem has a parent <dl>', function() { | ||
var checkArgs = checkSetup('<dl><dt id="target">My list item</dl>'); | ||
|
||
assert.isTrue(checks.dlitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
it('should fail if the dt element has an incorrect parent', function () { | ||
it('should fail if the dt element has an incorrect parent', function() { | ||
var checkArgs = checkSetup('<video><dt id="target">My list item</video>'); | ||
|
||
assert.isFalse(checks.dlitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
it('should pass if the dt element has a parent <dl> with role="list"', function () { | ||
var checkArgs = checkSetup('<dl role="list"><dt id="target">My list item</dl>'); | ||
it('should pass if the dt element has a parent <dl> with role="list"', function() { | ||
var checkArgs = checkSetup( | ||
'<dl role="list"><dt id="target">My list item</dl>' | ||
); | ||
assert.isTrue(checks.dlitem.evaluate.apply(null, checkArgs)); | ||
}) | ||
}); | ||
|
||
it('should fail if the dt element has a parent <dl> with role="presentation"', function () { | ||
var checkArgs = checkSetup('<dl role="presentation"><dt id="target">My list item</dl>'); | ||
it('should fail if the dt element has a parent <dl> with role="presentation"', function() { | ||
var checkArgs = checkSetup( | ||
'<dl role="presentation"><dt id="target">My list item</dl>' | ||
); | ||
assert.isFalse(checks.dlitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
it('should fail if the dt element has a parent <dl> with a changed role', function(){ | ||
var checkArgs = checkSetup('<dl role="menubar"><dt id="target">My list item</dl>'); | ||
it('should fail if the dt element has a parent <div> with role="list"', function() { | ||
var checkArgs = checkSetup( | ||
'<div role="list"><dt id="target">My list item</div>' | ||
); | ||
assert.isFalse(checks.dlitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
(shadowSupport.v1 ? it : xit)('should return true in a shadow DOM pass', function () { | ||
var node = document.createElement('div'); | ||
node.innerHTML = '<dt>My list item </dt>'; | ||
var shadow = node.attachShadow({ mode: 'open' }); | ||
shadow.innerHTML = '<dl><slot></slot></dl>'; | ||
|
||
var checkArgs = checkSetup(node, 'dt'); | ||
it('should pass if the dt element has a parent <dl> with an abstract role', function() { | ||
var checkArgs = checkSetup( | ||
'<dl role="section"><dt id="target">My list item</dl>' | ||
); | ||
assert.isTrue(checks.dlitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
(shadowSupport.v1 ? it : xit)('should return false in a shadow DOM fail', function () { | ||
var node = document.createElement('div'); | ||
node.innerHTML = '<dt>My list item </dt>'; | ||
var shadow = node.attachShadow({ mode: 'open' }); | ||
shadow.innerHTML = '<div><slot></slot></div>'; | ||
it('should pass if the dt element has a parent <dl> with an invalid role', function() { | ||
var checkArgs = checkSetup( | ||
'<dl role="invalid-role"><dt id="target">My list item</dl>' | ||
); | ||
assert.isTrue(checks.dlitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
var checkArgs = checkSetup(node, 'dt'); | ||
it('should fail if the dt element has a parent <dl> with a changed role', function() { | ||
var checkArgs = checkSetup( | ||
'<dl role="menubar"><dt id="target">My list item</dl>' | ||
); | ||
assert.isFalse(checks.dlitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
}); | ||
|
||
(shadowSupport.v1 ? it : xit)( | ||
'should return true in a shadow DOM pass', | ||
function() { | ||
var node = document.createElement('div'); | ||
node.innerHTML = '<dt>My list item </dt>'; | ||
var shadow = node.attachShadow({ mode: 'open' }); | ||
shadow.innerHTML = '<dl><slot></slot></dl>'; | ||
|
||
var checkArgs = checkSetup(node, 'dt'); | ||
assert.isTrue(checks.dlitem.evaluate.apply(null, checkArgs)); | ||
} | ||
); | ||
|
||
(shadowSupport.v1 ? it : xit)( | ||
'should return false in a shadow DOM fail', | ||
function() { | ||
var node = document.createElement('div'); | ||
node.innerHTML = '<dt>My list item </dt>'; | ||
var shadow = node.attachShadow({ mode: 'open' }); | ||
shadow.innerHTML = '<div><slot></slot></div>'; | ||
|
||
var checkArgs = checkSetup(node, 'dt'); | ||
assert.isFalse(checks.dlitem.evaluate.apply(null, checkArgs)); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,78 @@ | ||
describe('listitem', function () { | ||
describe('listitem', function() { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var checkSetup = axe.testUtils.checkSetup; | ||
var shadowSupport = axe.testUtils.shadowSupport; | ||
|
||
afterEach(function () { | ||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('should pass if the listitem has a parent <ol>', function () { | ||
it('should pass if the listitem has a parent <ol>', function() { | ||
var checkArgs = checkSetup('<ol><li id="target">My list item</li></ol>'); | ||
assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
it('should pass if the listitem has a parent <ul>', function () { | ||
it('should pass if the listitem has a parent <ul>', function() { | ||
var checkArgs = checkSetup('<ul><li id="target">My list item</li></ul>'); | ||
assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
it('should pass if the listitem has a parent role=list', function () { | ||
var checkArgs = checkSetup('<div role="list"><li id="target">My list item</li></div>'); | ||
it('should pass if the listitem has a parent role=list', function() { | ||
var checkArgs = checkSetup( | ||
'<div role="list"><li id="target">My list item</li></div>' | ||
); | ||
assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
it('should fail if the listitem has an incorrect parent', function () { | ||
it('should fail if the listitem has an incorrect parent', function() { | ||
var checkArgs = checkSetup('<div><li id="target">My list item</li></div>'); | ||
assert.isFalse(checks.listitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
it('should fail if the listitem has a parent <ol> with changed role', function () { | ||
var checkArgs = checkSetup('<ol role="menubar"><li id="target">My list item</li></ol>'); | ||
it('should fail if the listitem has a parent <ol> with changed role', function() { | ||
var checkArgs = checkSetup( | ||
'<ol role="menubar"><li id="target">My list item</li></ol>' | ||
); | ||
assert.isFalse(checks.listitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
(shadowSupport.v1 ? it : xit)('should return true in a shadow DOM pass', function () { | ||
var node = document.createElement('div'); | ||
node.innerHTML = '<li>My list item </li>'; | ||
var shadow = node.attachShadow({ mode: 'open' }); | ||
shadow.innerHTML = '<ul><slot></slot></ul>'; | ||
var checkArgs = checkSetup(node, 'li'); | ||
it('should pass if the listitem has a parent <ol> with an invalid role', function() { | ||
var checkArgs = checkSetup( | ||
'<ol role="invalid-role"><li id="target">My list item</li></ol>' | ||
); | ||
assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
(shadowSupport.v1 ? it : xit)('should return false in a shadow DOM fail', function () { | ||
var node = document.createElement('div'); | ||
node.innerHTML = '<li>My list item </li>'; | ||
var shadow = node.attachShadow({ mode: 'open' }); | ||
shadow.innerHTML = '<div><slot></slot></div>'; | ||
var checkArgs = checkSetup(node, 'li'); | ||
assert.isFalse(checks.listitem.evaluate.apply(null, checkArgs)); | ||
it('should pass if the listitem has a parent <ol> with an abstract role', function() { | ||
var checkArgs = checkSetup( | ||
'<ol role="section"><li id="target">My list item</li></ol>' | ||
); | ||
assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
(shadowSupport.v1 ? it : xit)( | ||
'should return true in a shadow DOM pass', | ||
function() { | ||
var node = document.createElement('div'); | ||
node.innerHTML = '<li>My list item </li>'; | ||
var shadow = node.attachShadow({ mode: 'open' }); | ||
shadow.innerHTML = '<ul><slot></slot></ul>'; | ||
var checkArgs = checkSetup(node, 'li'); | ||
assert.isTrue(checks.listitem.evaluate.apply(null, checkArgs)); | ||
} | ||
); | ||
|
||
(shadowSupport.v1 ? it : xit)( | ||
'should return false in a shadow DOM fail', | ||
function() { | ||
var node = document.createElement('div'); | ||
node.innerHTML = '<li>My list item </li>'; | ||
var shadow = node.attachShadow({ mode: 'open' }); | ||
shadow.innerHTML = '<div><slot></slot></div>'; | ||
var checkArgs = checkSetup(node, 'li'); | ||
assert.isFalse(checks.listitem.evaluate.apply(null, checkArgs)); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters