Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(standards): add ariaRoles standard #2328

Merged
merged 13 commits into from
Jun 29, 2020
184 changes: 184 additions & 0 deletions lib/standards/aria-roles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Source: https://www.w3.org/TR/wai-aria-1.1/#roles

/* easiest way to see allowed roles is to filter out the global ones
from the list of inherited states and properties. The dpub spec
does not have the global list so you'll need to copy over from
the wai-aria one:

const globalAttrs = Array.from(
document.querySelectorAll('#global_states li')
).map(li => li.textContent.replace(/\s*\(.*\)/, ''));

const globalRoleAttrs = Array.from(
document.querySelectorAll('.role-inherited li')
).filter(li => globalAttrs.includes(li.textContent.replace(/\s*\(.*\)/, '')))

globalRoleAttrs.forEach(li => li.style.display = 'none');
WilcoFiers marked this conversation as resolved.
Show resolved Hide resolved
*/
const ariaRoles = {
alert: {
type: 'widget',
allowedAttrs: ['aria-expanded']
},
alertdialog: {
type: 'widget',
allowedAttrs: ['aria-expanded', 'aria-modal']
},
application: {
// Note: spec difference
type: 'landmark',
// Note: aria-expanded is not in the 1.1 spec but is
// consistently supported in ATs and was added in 1.2
allowedAttrs: ['aria-activedescendant', 'aria-expanded']
},
article: {
type: 'structure',
allowedAttrs: ['aria-posinset', 'aria-setsize', 'aria-expanded']
},
banner: {
type: 'landmark',
allowedAttrs: ['aria-expanded']
},
button: {
type: 'widget',
allowedAttrs: ['aria-expanded', 'aria-pressed'],
nameFromContent: true
},
cell: {
type: 'structure',
requiredContext: ['row'],
allowedAttrs: [
'aria-colindex',
'aria-colspan',
'aria-rowindex',
'aria-rowspan',
'aria-expanded'
],
nameFromContent: true
},
checkbox: {
type: 'widget',
requiredAttrs: ['aria-checked'],
// Note: aria-required is not in the 1.1 spec but is
// consistently supported in ATs and was added in 1.2
allowedAttrs: ['aria-readonly', 'aria-required'],
nameFromContent: true
},
columnheader: {
type: 'structure',
requiredContext: ['row'],
allowedAttrs: [
'aria-sort',
'aria-colindex',
'aria-colspan',
'aria-expanded',
'aria-readonly',
'aria-required',
'aria-rowindex',
'aria-rowspan',
'aria-selected'
],
nameFromContent: true
},
combobox: {
type: 'composite',
requiredOwned: ['textbox', 'listbox', 'tree', 'grid', 'dialog'],
requiredAttrs: ['aria-expanded'],
// Note: because aria-controls is not well supported we will not
// make it a required attribute even though it is required in the
// spec
allowedAttrs: [
'aria-controls',
'aria-autocomplete',
'aria-readonly',
'aria-required',
'aria-activedescendant',
'aria-orientation'
]
},
command: {
type: 'abstract'
},
complementary: {
type: 'landmark',
allowedAttrs: ['aria-expanded']
},
composite: {
type: 'abstract'
},
contentinfo: {
type: 'landmark',
allowedAttrs: ['aria-expanded']
},
definition: {
type: 'structure',
allowedAttrs: ['aria-expanded']
},
dialog: {
type: 'widget',
allowedAttrs: ['aria-expanded', 'aria-modal']
},
directory: {
type: 'structure',
allowedAttrs: ['aria-expanded']
},
document: {
type: 'structure',
allowedAttrs: ['aria-expanded']
},
feed: {
type: 'structure',
requiredOwned: ['article'],
allowedAttrs: ['aria-expanded']
},
figure: {
type: 'structure',
allowedAttrs: ['aria-expanded'],
// Note: spec difference
nameFromContent: true
},
form: {
type: 'landmark',
allowedAttrs: ['aria-expanded']
},
grid: {
type: 'composite',
requiredOwned: ['rowgroup', 'row'],
allowedAttrs: [
'aria-level',
'aria-multiselectable',
'aria-readonly',
'aria-activedescendant',
'aria-colcount',
'aria-expanded',
'aria-rowcount'
]
},
gridcell: {
type: 'widget',
requiredContext: ['row'],
allowedAttrs: [
'aria-readonly',
'aria-required',
'aria-selected',
'aria-colindex',
'aria-colspan',
'aria-expanded',
'aria-rowindex',
'aria-rowspan'
],
nameFromContent: true
},
group: {
type: 'structure',
allowedAttrs: ['aria-activedescendant', 'aria-expanded']
},
heading: {
type: 'structure',
requiredAttrs: ['aria-level'],
allowedAttrs: ['aria-expanded'],
nameFromContent: true
}
};

export default ariaRoles;