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(aria-hidden-focusable): report incomplete with onfocus #3407

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/checks/keyboard/focusable-disabled-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ function focusableDisabledEvaluate(node, options, virtualNode) {

this.relatedNodes(relatedNodes);

if (relatedNodes.length && isModalOpen()) {
if (relatedNodes.length === 0 || isModalOpen()) {
return true;
}

return relatedNodes.length === 0;
return relatedNodes.every(related => related.onfocus) ? undefined : false
}

export default focusableDisabledEvaluate;
1 change: 1 addition & 0 deletions lib/checks/keyboard/focusable-disabled.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"impact": "serious",
"messages": {
"pass": "No focusable elements contained within element",
"incomplete": "Check if the focusable elements immediately move the focus indicator",
"fail": "Focusable content should be disabled or be removed from the DOM"
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/checks/keyboard/focusable-not-tabbable-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ function focusableNotTabbableEvaluate(node, options, virtualNode) {

this.relatedNodes(relatedNodes);

if (relatedNodes.length > 0 && isModalOpen()) {
if (relatedNodes.length === 0 || isModalOpen()) {
return true;
}

return relatedNodes.length === 0;
return relatedNodes.every(related => related.onfocus) ? undefined : false
}

export default focusableNotTabbableEvaluate;
1 change: 1 addition & 0 deletions lib/checks/keyboard/focusable-not-tabbable.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"impact": "serious",
"messages": {
"pass": "No focusable elements contained within element",
"incomplete": "Check if the focusable elements immediately move the focus indicator",
"fail": "Focusable content should have tabindex='-1' or be removed from the DOM"
}
}
Expand Down
5 changes: 0 additions & 5 deletions test/act-mapping/aria-hidden-is-focusable.json

This file was deleted.

24 changes: 24 additions & 0 deletions test/checks/keyboard/focusable-disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,28 @@ describe('focusable-disabled', function() {
var actual = check.evaluate.apply(checkContext, params);
assert.isTrue(actual);
});

it('returns undefined when the control has onfocus', function () {
var params = checkSetup(
'<button aria-hidden="true" id="target" onfocus="redirectFocus()">Button</button>'
);
assert.isUndefined(check.evaluate.apply(checkContext, params));
});

it('returns undefined when all focusable controls have onfocus events', function () {
var params = checkSetup('<div aria-hidden="true" id="target">' +
' <button onfocus="redirectFocus()">button</button>' +
'</div>'
);
assert.isUndefined(check.evaluate.apply(checkContext, params));
});

it('returns false when some, but not all focusable controls have onfocus events', function () {
var params = checkSetup('<div aria-hidden="true" id="target">' +
' <button onfocus="redirectFocus()">button</button>' +
' <button>button</button>' +
'</div>'
);
assert.isFalse(check.evaluate.apply(checkContext, params));
});
});
25 changes: 25 additions & 0 deletions test/checks/keyboard/focusable-not-tabbable.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,29 @@ describe('focusable-not-tabbable', function() {
var actual = check.evaluate.apply(checkContext, params);
assert.isTrue(actual);
});

it('returns undefined when the control has onfocus', function () {
var params = checkSetup(
'<a href="/" aria-hidden="true" id="target" onfocus="redirectFocus()">Link</a>'
);
assert.isUndefined(check.evaluate.apply(checkContext, params));
});

it('returns undefined when all focusable controls have onfocus events', function () {
var params = checkSetup('<div aria-hidden="true" id="target">' +
' <a href="/" onfocus="redirectFocus()">First link</a>' +
' <a href="/" onfocus="redirectFocus()">Second link</a>' +
'</div>'
);
assert.isUndefined(check.evaluate.apply(checkContext, params));
});

it('returns false when some, but not all focusable controls have onfocus events', function () {
var params = checkSetup('<div aria-hidden="true" id="target">' +
' <a href="/" onfocus="redirectFocus()">First link</a>' +
' <a href="/"">Second link</a>' +
'</div>'
);
assert.isFalse(check.evaluate.apply(checkContext, params));
});
});