-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shadow DOM): Create commons virtual methods, for backward compat…
…ibility * feat(aria.label): Works without a virtualNode * feat: Add hasContentVirtual method * feat(is-offscreen): Add shadow DOM support * chore: Some code cleanup * feat(text.visible): Created text.visibleVirtual for shadowDOM * fix: Pass all tests that use accessibleText * feat: add shadow support to aria-required-children Closes #421 * test: use abstracted checkSetup from testutils * fix: get virtualNode with getNodeFromTree * test: More testing for accessibleText() # Conflicts: # lib/commons/dom/find-elms-in-context.js # lib/commons/text/accessible-text.js # test/checks/keyboard/focusable-no-name.js # test/checks/tables/same-caption-summary.js # test/commons/text/accessible-text.js * feat(aria-required-parent): add Shadow DOM support Closes #422 * fix: Rename text.label to text.labelVirtual * fix: Create aria.labelVirtual method
- Loading branch information
1 parent
e910d57
commit 86a4c25
Showing
21 changed files
with
259 additions
and
249 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
var labelText = axe.commons.text.label(virtualNode); | ||
var labelText = axe.commons.text.labelVirtual(virtualNode); | ||
return !labelText && !!(node.getAttribute('title') || node.getAttribute('aria-describedby')); |
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,39 @@ | ||
/*global axe, aria, dom, text */ | ||
/** | ||
* Gets the accessible ARIA label text of a given element | ||
* @see http://www.w3.org/WAI/PF/aria/roles#namecalculation | ||
* @param {Object} The virtualNode to test | ||
* @return {Mixed} String of visible text, or `null` if no label is found | ||
*/ | ||
aria.labelVirtual = function ({ actualNode }) { | ||
let ref, candidate; | ||
|
||
if (actualNode.getAttribute('aria-labelledby')) { | ||
// aria-labelledby | ||
ref = dom.idrefs(actualNode, 'aria-labelledby'); | ||
candidate = ref.map(function (thing) { | ||
const vNode = axe.utils.getNodeFromTree(axe._tree[0], thing); | ||
return vNode ? text.visibleVirtual(vNode, true) : ''; | ||
}).join(' ').trim(); | ||
|
||
if (candidate) { | ||
return candidate; | ||
} | ||
} | ||
|
||
// aria-label | ||
candidate = actualNode.getAttribute('aria-label'); | ||
if (candidate) { | ||
candidate = text.sanitize(candidate).trim(); | ||
if (candidate) { | ||
return candidate; | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
aria.label = function (node) { | ||
node = axe.utils.getNodeFromTree(axe._tree[0], node); | ||
return aria.labelVirtual(node); | ||
}; |
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
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
31 changes: 13 additions & 18 deletions
31
lib/commons/text/visible.js → lib/commons/text/visible-virtual.js
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,31 +1,26 @@ | ||
/*global text, dom */ | ||
/*global text, dom, axe */ | ||
|
||
/** | ||
* NOTE: when calculating the text or accessible text of a node that includes shadow | ||
* roots attached to it or its children, the flattened tree must be considered | ||
* rather than the "light DOM" | ||
*/ | ||
|
||
text.visible = function (element, screenReader, noRecursing) { | ||
'use strict'; | ||
|
||
var index, child, nodeValue, | ||
childNodes = element.children, | ||
length = childNodes.length, | ||
result = ''; | ||
|
||
for (index = 0; index < length; index++) { | ||
child = childNodes[index]; | ||
|
||
text.visibleVirtual = function (element, screenReader, noRecursing) { | ||
const result = element.children.map(child => { | ||
if (child.actualNode.nodeType === 3) { // filter on text nodes | ||
nodeValue = child.actualNode.nodeValue; | ||
const nodeValue = child.actualNode.nodeValue; | ||
if (nodeValue && dom.isVisible(element.actualNode, screenReader)) { | ||
result += nodeValue; | ||
return nodeValue; | ||
} | ||
|
||
} else if (!noRecursing) { | ||
result += text.visible(child, screenReader); | ||
return text.visibleVirtual(child, screenReader); | ||
} | ||
} | ||
|
||
}).join(''); | ||
return text.sanitize(result); | ||
}; | ||
|
||
text.visible = function (element, screenReader, noRecursing) { | ||
element = axe.utils.getNodeFromTree(axe._tree[0], element); | ||
return text.visibleVirtual(element, screenReader, noRecursing); | ||
}; |
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.