-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aria-errormessage): adds support for aria-errormessage (#517)
* fix(aria-errormessage): adds support for aria-errormessage * fix(aria-valid-attr-value): switches from `any` mode to `all`
- Loading branch information
1 parent
6b81a50
commit c96f58c
Showing
9 changed files
with
110 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
options = Array.isArray(options) ? options : []; | ||
|
||
var attr = node.getAttribute('aria-errormessage'), | ||
hasAttr = node.hasAttribute('aria-errormessage'); | ||
|
||
var doc = axe.commons.dom.getRootNode(node); | ||
|
||
function validateAttrValue() { | ||
var idref = attr && doc.getElementById(attr); | ||
if (idref) { | ||
return idref.getAttribute('role') === 'alert' || | ||
idref.getAttribute('aria-live') === 'assertive' || | ||
axe.utils.tokenList(node.getAttribute('aria-describedby') || '').indexOf(attr) > -1; | ||
} | ||
} | ||
|
||
// limit results to elements that actually have this attribute | ||
if (options.indexOf(attr) === -1 && hasAttr) { | ||
if (!validateAttrValue()) { | ||
this.data(attr); | ||
return false; | ||
} | ||
} | ||
|
||
return true; |
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,11 @@ | ||
{ | ||
"id": "aria-errormessage", | ||
"evaluate": "errormessage.js", | ||
"metadata": { | ||
"impact": "critical", | ||
"messages": { | ||
"pass": "Uses a supported aria-errormessage technique", | ||
"fail": "aria-errormessage value{{=it.data && it.data.length > 1 ? 's' : ''}} {{~it.data:value}} `{{=value}}{{~}}` must use a technique to announce the message (e.g., aria-live, aria-describedby, role=alert, etc.)" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
describe('aria-errormessage', function () { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
|
||
var checkContext = axe.testUtils.MockCheckContext(); | ||
|
||
afterEach(function () { | ||
fixture.innerHTML = ''; | ||
checkContext._data = null; | ||
}); | ||
|
||
it('should return false if aria-errormessage value is invalid', function () { | ||
var testHTML = '<div></div>'; | ||
testHTML += '<div id="plain"></div>'; | ||
fixture.innerHTML = testHTML; | ||
var target = fixture.children[0]; | ||
target.setAttribute('aria-errormessage', 'plain'); | ||
assert.isFalse(checks['aria-errormessage'].evaluate.call(checkContext, target)); | ||
}); | ||
|
||
it('should return true if aria-errormessage id is alert', function () { | ||
var testHTML = '<div></div>'; | ||
testHTML += '<div id="alert" role="alert"></div>'; | ||
fixture.innerHTML = testHTML; | ||
var target = fixture.children[0]; | ||
target.setAttribute('aria-errormessage', 'alert'); | ||
assert.isTrue(checks['aria-errormessage'].evaluate.call(checkContext, target)); | ||
}); | ||
|
||
it('should return true if aria-errormessage id is aria-live=assertive', function () { | ||
var testHTML = '<div></div>'; | ||
testHTML += '<div id="live" aria-live="assertive"></div>'; | ||
fixture.innerHTML = testHTML; | ||
var target = fixture.children[0]; | ||
target.setAttribute('aria-errormessage', 'live'); | ||
assert.isTrue(checks['aria-errormessage'].evaluate.call(checkContext, target)); | ||
}); | ||
|
||
it('should return true if aria-errormessage id is aria-describedby', function () { | ||
var testHTML = '<div></div>'; | ||
testHTML += '<div id="plain"></div>'; | ||
fixture.innerHTML = testHTML; | ||
var target = fixture.children[0]; | ||
target.setAttribute('aria-errormessage', 'plain'); | ||
target.setAttribute('aria-describedby', 'plain'); | ||
assert.isTrue(checks['aria-errormessage'].evaluate.call(checkContext, target)); | ||
}); | ||
}); |
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