-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aria-roles): exception for focus-order-semantics
add `window` to has-widget-role, renamed Refs: #4371
- Loading branch information
1 parent
417e6b1
commit facd65f
Showing
7 changed files
with
148 additions
and
596 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getRoleType } from '../../commons/aria'; | ||
|
||
const acceptedRoles = { | ||
widget: true, | ||
composite: true, | ||
window: true | ||
}; | ||
|
||
/** | ||
* Check if an elements `role` attribute uses any widget, composite, window abstract role values. | ||
* | ||
* Widget roles are taken from the `ariaRoles` standards object from the roles `type` property. | ||
* | ||
* @memberof checks | ||
* @return {Boolean} True if the element uses a `widget`, `composite`, or `window` abstract role (type). False otherwise. | ||
*/ | ||
// # TODO: change to abstract role for widget and window | ||
function hasWidgetOrWindowRoleEvaluate(node) { | ||
const role = node.getAttribute('role'); | ||
if (role === null) { | ||
return false; | ||
} | ||
return !!acceptedRoles[getRoleType(role)]; | ||
} | ||
|
||
export default hasWidgetOrWindowRoleEvaluate; |
4 changes: 2 additions & 2 deletions
4
lib/checks/aria/has-widget-role.json → ...hecks/aria/has-widget-or-window-role.json
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 was deleted.
Oops, something went wrong.
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,118 @@ | ||
describe('has-widget-or-window-role', function () { | ||
'use strict'; | ||
|
||
let node; | ||
const fixture = document.getElementById('fixture'); | ||
const checkContext = axe.testUtils.MockCheckContext(); | ||
const evaluate = currentNode => | ||
axe.testUtils | ||
.getCheckEvaluate('has-widget-or-window-role') | ||
.call(checkContext, currentNode); | ||
const roles = { | ||
widget: { | ||
button: true, | ||
checkbox: true, | ||
gridcell: true, | ||
link: true, | ||
menuitem: true, | ||
menuitemcheckbox: true, | ||
menuitemradio: true, | ||
option: true, | ||
progressbar: true, | ||
radio: true, | ||
scrollbar: true, | ||
searchbox: true, | ||
slider: true, | ||
spinbutton: true, | ||
switch: true, | ||
tab: true, | ||
tabpanel: true, | ||
textbox: true, | ||
treeitem: true | ||
}, | ||
composite: { | ||
combobox: true, | ||
grid: true, | ||
listbox: true, | ||
menu: true, | ||
menubar: true, | ||
radiogroup: true, | ||
tablist: true, | ||
tree: true, | ||
treegrid: true, | ||
|
||
application: false, | ||
article: false, | ||
cell: false, | ||
columnheader: false, | ||
definition: false, | ||
directory: false, | ||
document: false, | ||
feed: false, | ||
figure: false, | ||
group: false, | ||
heading: false, | ||
img: false, | ||
list: false, | ||
listitem: false, | ||
math: false, | ||
none: false, | ||
note: false, | ||
presentation: false, | ||
row: false, | ||
rowgroup: false, | ||
rowheader: false, | ||
table: false, | ||
term: false, | ||
toolbar: false | ||
}, | ||
window: { | ||
alertdialog: true, | ||
dialog: true | ||
}, | ||
landmark: { | ||
banner: false, | ||
complimentary: false, | ||
contentinfo: false, | ||
form: false, | ||
name: false, | ||
navigation: false, | ||
region: false, | ||
search: false | ||
} | ||
}; | ||
|
||
afterEach(function () { | ||
node.innerHTML = ''; | ||
checkContext._data = null; | ||
}); | ||
|
||
it('should return false for elements with no role', function () { | ||
node = document.createElement('div'); | ||
fixture.appendChild(node); | ||
|
||
assert.isFalse(evaluate(node)); | ||
}); | ||
|
||
it('should return false for elements with nonsensical roles', function () { | ||
node = document.createElement('div'); | ||
node.setAttribute('role', 'buttonbuttonbutton'); | ||
fixture.appendChild(node); | ||
|
||
assert.isFalse(evaluate(node)); | ||
}); | ||
|
||
Object.keys(roles).forEach(category => { | ||
describe(category, function () { | ||
Object.keys(roles[category]).forEach(role => { | ||
it(`should return ${roles[category][role]} for role="${role}"`, function () { | ||
node = document.createElement('div'); | ||
node.setAttribute('role', role); | ||
fixture.appendChild(node); | ||
|
||
assert.equal(evaluate(node), roles[category][role]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.