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

fix: Solve several accessible-name issues #1163

Merged
merged 29 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8c80f14
chore(WIP): rewrite accessibleText
WilcoFiers Sep 20, 2018
82e5c74
Merge branch 'develop' into a11y-name
WilcoFiers Sep 26, 2018
9d2451e
chore: More refactoring for accname
WilcoFiers Sep 26, 2018
305c864
chore(WIP): More improvements to accessibleName
WilcoFiers Oct 10, 2018
8501f34
feat: Reimplement accessible name computation
WilcoFiers Oct 10, 2018
dec7220
chore: All accessible name tests passing
WilcoFiers Oct 13, 2018
abb0673
chore(accName): All tests passing
WilcoFiers Oct 13, 2018
4de5489
chore: Add tests
WilcoFiers Nov 9, 2018
a98448b
chore: Test form-control-value
WilcoFiers Nov 23, 2018
e264958
chore: Merge develop
WilcoFiers Nov 23, 2018
1aded4a
chore: Refactor and add docs to accessible-text
WilcoFiers Nov 24, 2018
6e67b52
chore: Add tests for namedFromContents
WilcoFiers Nov 25, 2018
2a5020e
chore: Refactor subtreeText method
WilcoFiers Nov 25, 2018
6ff002b
chore: Refactor native accessible text methods
WilcoFiers Nov 25, 2018
4c6c351
chore: Coverage for text.labelText
WilcoFiers Dec 3, 2018
6917ec9
Merge branch 'develop' into a11y-name
WilcoFiers Jan 7, 2019
73ded40
Merge branch 'develop' into a11y-name
jeeyyy Jan 23, 2019
2244ed2
fix: update to axe.commons.matches usage
jeeyyy Jan 23, 2019
6c35b51
Merge branch 'develop' into a11y-name
jeeyyy Jan 23, 2019
9bddd36
test: fix nativeTextboxValue tests
jeeyyy Jan 23, 2019
3f9a969
test: fix failing tests
jeeyyy Jan 25, 2019
1227102
chore: merge from develop
jeeyyy Jan 25, 2019
dfa1bd7
fix: compute includeHidden as a part of accessibleName fn
jeeyyy Jan 25, 2019
d0f45e7
fix: do not mutate context in accessibleText
jeeyyy Jan 25, 2019
c3a1bdc
Merge branch 'develop' into a11y-name
jeeyyy Jan 25, 2019
c4f7b2b
Merge branch 'develop' into a11y-name
WilcoFiers Feb 5, 2019
516952c
chore: Refactor a11yText method for readability
WilcoFiers Feb 5, 2019
8fc69a3
chore: Update a11yText test results
WilcoFiers Feb 5, 2019
994155b
Merge branch 'develop' into a11y-name
WilcoFiers Feb 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/checks/shared/aria-label.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
var label = node.getAttribute('aria-label');
return !!(label ? axe.commons.text.sanitize(label).trim() : '');
return !!axe.commons.aria.getAriaLabelText(node);
6 changes: 1 addition & 5 deletions lib/checks/shared/aria-labelledby.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
var getIdRefs = axe.commons.dom.idrefs;

return getIdRefs(node, 'aria-labelledby').some(function(elm) {
return elm && axe.commons.text.accessibleText(elm, true);
});
return !!axe.commons.aria.getAriaLabelledbyText(node);
9 changes: 9 additions & 0 deletions lib/commons/aria/get-aria-label-text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* global aria, text */
aria.getAriaLabelText = function getAriaLabelText(node) {
jeeyyy marked this conversation as resolved.
Show resolved Hide resolved
node = node.actualNode || node;
if (node.nodeType !== 1) {
return '';
}
var label = node && node.getAttribute('aria-label');
return label ? text.sanitize(label) : '';
};
37 changes: 37 additions & 0 deletions lib/commons/aria/get-aria-labelledby-text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* global aria, dom, text */
aria.getAriaLabelledbyText = function getAriaLabelledbyText(node, context) {
node = node.actualNode || node;
/**
* Note: The there are significant difference in how many "leads" browsers follow.
* - Firefox stops after the first IDREF, so it
* doesn't follow aria-labelledby after a for:>ID ref.
* - Chrome seems to just keep iterating no matter how many levels deep.
* - AccName-AAM 1.1 suggests going one level deep, but to treat
* each ref type separately.
*
* Axe-core's implementation behaves most closely like Firefox as it seems
* to be the most common deniminator. Main difference is that Firefox
* includes the value of form controls in addition to aria-label(s),
* something no other browser seems to do. Axe doesn't do that.
*/
if (
node.nodeType !== 1 ||
context.inLabelledByContext ||
context.inControlContext
) {
return '';
}

const refs = dom.idrefs(node, 'aria-labelledby').filter(elm => elm);
jeeyyy marked this conversation as resolved.
Show resolved Hide resolved
return refs.reduce((accessibleName, elm) => {
const accessibleNameAdd = text.accessibleText(elm, {
// Prevent the infinite reference loop:
inLabelledByContext: true,
// Allow hidden content if
includeHidden: !dom.isVisible(elm, true),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the dom.isHidden?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to look if this is part of the accessibility tree, axe.utils.isHidden doesn't do that.

...context
});

return (accessibleName + ' ' + accessibleNameAdd).trim();
}, '');
};
10 changes: 10 additions & 0 deletions lib/commons/aria/get-owned.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* global aria, dom */
aria.getOwnedVirtual = function getOwned({ actualNode, children }) {
return dom.idrefs(actualNode, 'aria-owns').reduce((ownedElm, element) => {
if (element) {
let virtualNode = axe.utils.getNodeFromTree(axe._tree[0], element);
ownedElm.push(virtualNode);
}
return ownedElm;
}, children);
};
4 changes: 4 additions & 0 deletions lib/commons/aria/get-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ aria.getRole = function getRole(
node,
{ noImplicit, fallback, abstracts, dpub } = {}
) {
node = node.actualNode || node;
if (node.nodeType !== 1) {
return null;
}
const roleAttr = (node.getAttribute('role') || '').trim().toLowerCase();
const roleList = fallback ? axe.utils.tokenList(roleAttr) : [roleAttr];

Expand Down