-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(checks): deprecate role-none and role-presentation for presentat…
…ional-role (#2503) * feat(checks): deprecate role-none and role-presentation for presentational-role * fix locales * Update lib/checks/shared/presentational-role.json Co-authored-by: Wilco Fiers <[email protected]> * Update lib/checks/shared/presentational-role.json Co-authored-by: Wilco Fiers <[email protected]> Co-authored-by: Wilco Fiers <[email protected]>
- Loading branch information
1 parent
63262bb
commit cef54a0
Showing
34 changed files
with
392 additions
and
81 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { getExplicitRole, getRole } from '../../commons/aria'; | ||
import { getGlobalAriaAttrs } from '../../commons/standards'; | ||
import { isFocusable } from '../../commons/dom'; | ||
|
||
function presentationalRoleEvaluate(node, options, virtualNode) { | ||
const role = getRole(virtualNode); | ||
const explicitRole = getExplicitRole(virtualNode); | ||
|
||
if (['presentation', 'none'].includes(role)) { | ||
this.data({ role }); | ||
return true; | ||
} | ||
|
||
// if the user didn't intended to make this presentational we fail | ||
if (!['presentation', 'none'].includes(explicitRole)) { | ||
return false; | ||
} | ||
|
||
// user intended to make this presentational so inform them of | ||
// problems caused by role conflict resolution | ||
const hasGlobalAria = getGlobalAriaAttrs().some(attr => | ||
virtualNode.hasAttr(attr) | ||
); | ||
const focusable = isFocusable(virtualNode); | ||
let messageKey; | ||
|
||
if (hasGlobalAria && !focusable) { | ||
messageKey = 'globalAria'; | ||
} else if (!hasGlobalAria && focusable) { | ||
messageKey = 'focusable'; | ||
} else { | ||
messageKey = 'both'; | ||
} | ||
|
||
this.data({ | ||
messageKey, | ||
role | ||
}); | ||
return false; | ||
} | ||
|
||
export default presentationalRoleEvaluate; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"id": "presentational-role", | ||
"evaluate": "presentational-role-evaluate", | ||
"metadata": { | ||
"impact": "minor", | ||
"messages": { | ||
"pass": "Element's default semantics were overriden with role=\"${data.role}\"", | ||
"fail": { | ||
"default": "Element's default semantics were not overridden with role=\"none\" or role=\"presentation\"", | ||
"globalAria": "Element's role is not presentational because it has a global ARIA attribute", | ||
"focusable": "Element's role is not presentational because it is focusable", | ||
"both": "Element's role is not presentational because it has a global ARIA attribute and is focusable" | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
describe('presentational-role', function() { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var queryFixture = axe.testUtils.queryFixture; | ||
var checkEvaluate = axe.testUtils.getCheckEvaluate('presentational-role'); | ||
var checkContext = axe.testUtils.MockCheckContext(); | ||
|
||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
checkContext.reset(); | ||
}); | ||
|
||
it('should detect role="none" on the element', function() { | ||
var vNode = queryFixture('<div id="target" role="none"></div>'); | ||
|
||
assert.isTrue(checkEvaluate.call(checkContext, null, null, vNode)); | ||
assert.deepEqual(checkContext._data.role, 'none'); | ||
}); | ||
|
||
it('should detect role="presentation" on the element', function() { | ||
var vNode = queryFixture('<div id="target" role="presentation"></div>'); | ||
|
||
assert.isTrue(checkEvaluate.call(checkContext, null, null, vNode)); | ||
assert.deepEqual(checkContext._data.role, 'presentation'); | ||
}); | ||
|
||
it('should return false when role !== none', function() { | ||
var vNode = queryFixture('<div id="target" role="cats"></div>'); | ||
|
||
assert.isFalse(checkEvaluate.call(checkContext, null, null, vNode)); | ||
}); | ||
|
||
it('should return false when there is no role attribute', function() { | ||
var vNode = queryFixture('<div id="target"></div>'); | ||
|
||
assert.isFalse(checkEvaluate.call(checkContext, null, null, vNode)); | ||
}); | ||
|
||
it('should return false when the element is focusable', function() { | ||
var vNode = queryFixture( | ||
'<button id="target" role="none">Still a button</button>' | ||
); | ||
|
||
assert.isFalse(checkEvaluate.call(checkContext, null, null, vNode)); | ||
assert.deepEqual(checkContext._data.messageKey, 'focusable'); | ||
}); | ||
|
||
it('should return false when the element has global aria attributes', function() { | ||
var vNode = queryFixture( | ||
'<img id="target" role="none" aria-live="assertive" />' | ||
); | ||
|
||
assert.isFalse(checkEvaluate.call(checkContext, null, null, vNode)); | ||
assert.deepEqual(checkContext._data.messageKey, 'globalAria'); | ||
}); | ||
|
||
it('should return false when the element has global aria attributes and is focusable', function() { | ||
var vNode = queryFixture( | ||
'<button id="target" role="none" aria-live="assertive">Still a button</button>' | ||
); | ||
|
||
assert.isFalse(checkEvaluate.call(checkContext, null, null, vNode)); | ||
assert.deepEqual(checkContext._data.messageKey, 'both'); | ||
}); | ||
}); |
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
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
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
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
Oops, something went wrong.