Skip to content
This repository was archived by the owner on Dec 7, 2022. It is now read-only.

Commit b64579d

Browse files
joschaaddyosmani
authored andcommitted
fix: axs.utils.getAriaIdReferrers can return null for missing referrers which breaks roleTooltipRequiresDescribedby (#258)
1 parent ce211b8 commit b64579d

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/js/AccessibilityUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ axs.utils.getQuerySelectorText = function(obj) {
10121012
* single ID reference.
10131013
* @param {Element} element a potential referent.
10141014
* @param {string=} opt_attributeName Name of an ARIA attribute to limit the results to, e.g. 'aria-owns'.
1015-
* @return {NodeList} The elements that refer to this element.
1015+
* @return {NodeList} The elements that refer to this element or null.
10161016
*/
10171017
axs.utils.getAriaIdReferrers = function(element, opt_attributeName) {
10181018
var propertyToSelector = function(propertyKey) {

test/audits/role-tooltip-requires-described-by-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,17 @@ test('a tooltip without an ID doesn\'t cause an exception', function() {
9191
ok(false, 'Running roleTooltipRequiresDescribedby threw an exception: ' + e.message);
9292
}
9393
});
94+
95+
test('role tooltip with a corresponding describedby of a missing element id should fail', function() {
96+
var fixture = document.getElementById('qunit-fixture');
97+
var tooltip = document.createElement('div');
98+
var trigger = document.createElement('div');
99+
fixture.appendChild(tooltip);
100+
fixture.appendChild(trigger);
101+
tooltip.setAttribute('role', 'tooltip');
102+
trigger.setAttribute('aria-describedby', 'tooltip1');
103+
deepEqual(
104+
axs.AuditRules.getRule('roleTooltipRequiresDescribedby').run({ scope: fixture }),
105+
{ elements: [tooltip], result: axs.constants.AuditResult.FAIL }
106+
);
107+
});

0 commit comments

Comments
 (0)