-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from browserstack/release-3.4.0
release-3.4.0
- Loading branch information
Showing
7 changed files
with
66 additions
and
2 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,46 @@ | ||
/** | ||
* Get the accessible name based on aria-describedby | ||
* | ||
* @deprecated Do not use Element directly. Pass VirtualNode instead | ||
* @param {VirtualNode|Element} element | ||
* @param {Object} context | ||
* @property {Bool} inLabelledByContext Whether or not the lookup is part of aria-describedby reference | ||
* @property {Bool} inControlContext Whether or not the lookup is part of a native label reference | ||
* @property {Element} startNode First node in accessible name computation | ||
* @property {Bool} debug Enable logging for formControlValue | ||
* @return {string} Concatenated text value for referenced elements | ||
*/ | ||
function ariadescribedbyText(element, context = {}) { | ||
const { vNode } = axe.utils.nodeLookup(element); | ||
if (vNode?.props.nodeType !== 1) { | ||
return ''; | ||
} | ||
|
||
if ( | ||
vNode.props.nodeType !== 1 || | ||
context.inLabelledByContext || | ||
context.inControlContext || | ||
!vNode.attr('aria-describedby') | ||
) { | ||
return ''; | ||
} | ||
|
||
const refs = axe.commons.dom | ||
.idrefs(vNode, 'aria-describedby') | ||
.filter(elm => elm); | ||
return refs.reduce((accessibleName, elm) => { | ||
const accessibleNameAdd = axe.commons.text.accessibleText(elm, { | ||
// Prevent the infinite reference loop: | ||
inLabelledByContext: true, | ||
startNode: context.startNode || vNode, | ||
...context | ||
}); | ||
|
||
if (!accessibleName) { | ||
return accessibleNameAdd; | ||
} | ||
return `${accessibleName} ${accessibleNameAdd}`; | ||
}, ''); | ||
} | ||
|
||
export default ariadescribedbyText; |
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