Skip to content

Commit

Permalink
fix(aria-hidden-focusable): report incomplete with onfocus (#3407)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers authored and straker committed May 12, 2022
1 parent a459075 commit 6755e89
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 11 deletions.
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));
});
});

0 comments on commit 6755e89

Please sign in to comment.