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: check for hidden elements on aria-errormessage #3156

Merged
merged 9 commits into from
Sep 24, 2021
Merged
Changes from 1 commit
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
Next Next commit
add visible checks and tests
Zidious committed Sep 13, 2021
commit 1a028793ab7375cd1e483cfd6bdbf582421bd5dc
10 changes: 9 additions & 1 deletion lib/checks/aria/aria-errormessage-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import standards from '../../standards';
import { idrefs } from '../../commons/dom';
import { tokenList } from '../../core/utils';

import { isVisible } from '../../commons/dom';
/**
* Check if `aria-errormessage` references an element that also uses a technique to announce the message (aria-live, aria-describedby, etc.).
*
@@ -55,13 +55,21 @@ function ariaErrormessageEvaluate(node, options, virtualNode) {
}

if (idref) {
if (!isVisible(idref)) {
this.data({
messageKey: 'hidden',
values: tokenList(attr)
});
return false;
}
return (
idref.getAttribute('role') === 'alert' ||
idref.getAttribute('aria-live') === 'assertive' ||
idref.getAttribute('aria-live') === 'polite' ||
tokenList(virtualNode.attr('aria-describedby')).indexOf(attr) > -1
);
}

return;
}

3 changes: 2 additions & 1 deletion lib/checks/aria/aria-errormessage.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,8 @@
"pass": "aria-errormessage exists and references elements visible to screen readers that use a supported aria-errormessage technique",
"fail": {
"singular": "aria-errormessage value `${data.values}` must use a technique to announce the message (e.g., aria-live, aria-describedby, role=alert, etc.)",
"plural": "aria-errormessage values `${data.values}` must use a technique to announce the message (e.g., aria-live, aria-describedby, role=alert, etc.)"
"plural": "aria-errormessage values `${data.values}` must use a technique to announce the message (e.g., aria-live, aria-describedby, role=alert, etc.)",
"hidden": "aria-errormessage value `${data.values}` cannot be reference a hidden element"
},
"incomplete": {
"singular": "ensure aria-errormessage value `${data.values}` references an existing element",
48 changes: 48 additions & 0 deletions test/checks/aria/errormessage.js
Original file line number Diff line number Diff line change
@@ -144,6 +144,54 @@ describe('aria-errormessage', function() {
);
});

it('should return false when hidden attribute is used', function() {
var vNode = queryFixture(
'<input type="text" id="target" aria-invalid="true" aria-errormessage="id-message-1"></div>' +
'<div id="id-message-1" hidden>Error message 1</div>'
);
assert.isFalse(
axe.testUtils
.getCheckEvaluate('aria-errormessage')
.call(checkContext, null, null, vNode)
);
assert.deepEqual(checkContext._data, {
messageKey: 'hidden',
values: ['id-message-1']
});
});

it('should return false when display: "none" is used', function() {
var vNode = queryFixture(
'<input type="text" id="target" aria-invalid="true" aria-errormessage="id-message-1"></div>' +
'<div id="id-message-1" style="display: none">Error message 1</div>'
);
assert.isFalse(
axe.testUtils
.getCheckEvaluate('aria-errormessage')
.call(checkContext, null, null, vNode)
);
assert.deepEqual(checkContext._data, {
messageKey: 'hidden',
values: ['id-message-1']
});
});

it('should return false when visibility: "hidden" is used', function() {
var vNode = queryFixture(
'<input type="text" id="target" aria-invalid="true" aria-errormessage="id-message-1"></div>' +
'<div id="id-message-1" style="visibility: hidden">Error message 1</div>'
);
assert.isFalse(
axe.testUtils
.getCheckEvaluate('aria-errormessage')
.call(checkContext, null, null, vNode)
);
assert.deepEqual(checkContext._data, {
messageKey: 'hidden',
values: ['id-message-1']
});
});

(shadowSupported ? it : xit)(
'should return undefined if aria-errormessage value crosses shadow boundary',
function() {