-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: convert commons.aria to ES Modules * import outside aria
- Loading branch information
Showing
35 changed files
with
2,906 additions
and
2,752 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
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,20 @@ | ||
import lookupTable from './lookup-table'; | ||
|
||
/** | ||
* Get allowed attributes for a given role | ||
* @method allowedAttr | ||
* @memberof axe.commons.aria | ||
* @instance | ||
* @param {String} role The role to check | ||
* @return {Array} | ||
*/ | ||
function allowedAttr(role) { | ||
const roles = lookupTable.role[role]; | ||
const attr = (roles && roles.attributes && roles.attributes.allowed) || []; | ||
const requiredAttr = | ||
(roles && roles.attributes && roles.attributes.required) || []; | ||
|
||
return attr.concat(lookupTable.globalAttributes).concat(requiredAttr); | ||
} | ||
|
||
export default allowedAttr; |
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,20 @@ | ||
/* global aria */ | ||
|
||
/** | ||
* Get the text value of aria-label, if any | ||
* | ||
* @deprecated Do not use Element directly. Pass VirtualNode instead | ||
* @param {VirtualNode|Element} element | ||
* @return {string} ARIA label | ||
*/ | ||
aria.arialabelText = function arialabelText(node) { | ||
function arialabelText(node) { | ||
// TODO: es-module-AbstractVirtualNode | ||
if (node instanceof axe.AbstractVirtualNode === false) { | ||
if (node.nodeType !== 1) { | ||
return ''; | ||
} | ||
// TODO: es-module-utils.getNodeFromTree | ||
node = axe.utils.getNodeFromTree(node); | ||
} | ||
return node.attr('aria-label') || ''; | ||
}; | ||
} | ||
|
||
export default arialabelText; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
/* global aria, dom */ | ||
/* global dom */ | ||
|
||
/** | ||
* Get an element's owned elements | ||
* | ||
* @param {VirtualNode} element | ||
* @return {VirtualNode[]} Owned elements | ||
*/ | ||
aria.getOwnedVirtual = function getOwned({ actualNode, children }) { | ||
function getOwnedVirtual({ actualNode, children }) { | ||
if (!actualNode || !children) { | ||
throw new Error('getOwnedVirtual requires a virtual node'); | ||
} | ||
// TODO: Check that the element has a role | ||
// TODO: Descend into children with role=presentation|none | ||
// TODO: Exclude descendents owned by other elements | ||
|
||
// TODO: es-module-dom.idrefs | ||
return dom.idrefs(actualNode, 'aria-owns').reduce((ownedElms, element) => { | ||
if (element) { | ||
// TODO: es-module-utils.getNodeFromTree | ||
const virtualNode = axe.utils.getNodeFromTree(element); | ||
ownedElms.push(virtualNode); | ||
} | ||
return ownedElms; | ||
}, children); | ||
}; | ||
} | ||
|
||
export default getOwnedVirtual; |
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 @@ | ||
import lookupTable from './lookup-table'; | ||
|
||
/** | ||
* Get the "type" of role; either widget, composite, abstract, landmark or `null` | ||
* @method getRoleType | ||
* @memberof axe.commons.aria | ||
* @instance | ||
* @param {String} role The role to check | ||
* @return {Mixed} String if a matching role and its type are found, otherwise `null` | ||
*/ | ||
function getRoleType(role) { | ||
var r = lookupTable.role[role]; | ||
return (r && r.type) || null; | ||
} | ||
|
||
export default getRoleType; |
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,17 @@ | ||
import lookupTable from './lookup-table'; | ||
|
||
/** | ||
* Get the roles that have a certain "type" | ||
* @method getRolesByType | ||
* @memberof axe.commons.aria | ||
* @instance | ||
* @param {String} roleType The roletype to check | ||
* @return {Array} Array of roles that match the type | ||
*/ | ||
function getRolesByType(roleType) { | ||
return Object.keys(lookupTable.role).filter(function(r) { | ||
return lookupTable.role[r].type === roleType; | ||
}); | ||
} | ||
|
||
export default getRolesByType; |
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,19 @@ | ||
import lookupTable from './lookup-table'; | ||
|
||
/** | ||
* Get the roles that get name from the element's contents | ||
* @method getRolesWithNameFromContents | ||
* @memberof axe.commons.aria | ||
* @instance | ||
* @return {Array} Array of roles that match the type | ||
*/ | ||
function getRolesWithNameFromContents() { | ||
return Object.keys(lookupTable.role).filter(function(r) { | ||
return ( | ||
lookupTable.role[r].nameFrom && | ||
lookupTable.role[r].nameFrom.indexOf('contents') !== -1 | ||
); | ||
}); | ||
} | ||
|
||
export default getRolesWithNameFromContents; |
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,24 @@ | ||
import lookupTable from './lookup-table'; | ||
|
||
/** | ||
* Get a list of CSS selectors of nodes that have an implicit role | ||
* @method implicitNodes | ||
* @memberof axe.commons.aria | ||
* @instance | ||
* @param {String} role The role to check | ||
* @return {Mixed} Either an Array of CSS selectors or `null` if there are none | ||
*/ | ||
function implicitNodes(role) { | ||
'use strict'; | ||
|
||
let implicit = null; | ||
const roles = lookupTable.role[role]; | ||
|
||
if (roles && roles.implicit) { | ||
// TODO: es-module-utils.clone | ||
implicit = axe.utils.clone(roles.implicit); | ||
} | ||
return implicit; | ||
} | ||
|
||
export default implicitNodes; |
Oops, something went wrong.