Skip to content

Commit f013f8a

Browse files
shunguoytombrunet
andauthored
fix circular structure caused by aria-owns (IBMa#2164)
Co-authored-by: Tom Brunet <thbrunet@us.ibm.com>
1 parent f039d21 commit f013f8a

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

karma.conf.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
//{ pattern: 'test/v2/checker/accessibility/rules/label_name_visible_ruleunit/label_offscreen.html', watched: true },
4848
//{ pattern: 'test/v2/checker/accessibility/rules/aria_role_valid_ruleunit/td_attribute_invalid_copy.html', watched: true },
4949
//{ pattern: 'test/v2/checker/accessibility/rules/text_block_heading_ruleunit/Headings-noneUsedEmphasizedText.html', watched: true },
50-
{ pattern: 'test/v2/checker/accessibility/rules/aria_landmark_name_unique_ruleunit/*.html', watched: true },
50+
//{ pattern: 'test/v2/checker/accessibility/rules/aria_landmark_name_unique_ruleunit/*.html', watched: true },
5151
// { pattern: 'test/v2/checker/accessibility/rules/aria_parent_required_ruleunit/webComponentPass2.html', watched: true },
5252

5353

54-
// { pattern: 'test/**/*_ruleunit/*.html', watched: true },
55-
// { pattern: 'test/**/*_ruleunit/*.htm', watched: true },
54+
{ pattern: 'test/**/*_ruleunit/*.html', watched: true },
55+
{ pattern: 'test/**/*_ruleunit/*.htm', watched: true },
5656
// all files ending in "_test"
5757
// { pattern: 'test/*_test.js', watched: true },
5858
{ pattern: 'test/**/*_test.js', watched: true }

src/v2/aria/ARIAMapper.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,45 @@ export class ARIAMapper extends CommonMapper {
9595
for (let iId=0; iId < ownIds.length; ++iId) {
9696
const owned = doc.getElementById(ownIds[iId]);
9797
//ignore if the aria-owns point to the element itself
98-
if (owned && !DOMUtil.sameNode(owner, owned)) {
99-
CacheUtil.setCache(owned, "aria-owned", owner);
98+
//if (owned && !DOMUtil.sameNode(owner, owned)) {
99+
// CacheUtil.setCache(owned, "aria-owned", owner);
100+
//}
101+
/**
102+
* circular hierarchy check:
103+
* (1) the owned element is neither the same element with the owner nor any ascendant of the owner
104+
* (2) any child with aria-owns cannot point to the owner or any ascendant of the owner
105+
*/
106+
if (owned && !DOMUtil.sameNode(owner, owned)) {
107+
// check if the owned with aria-owns that points to another element
108+
let ownedNodes = [];
109+
const sub_owners = owned.querySelectorAll("[aria-owns]");
110+
for (let i = 0; i < sub_owners.length; ++i) {
111+
const sub_owner = sub_owners[i];
112+
const sub_ownIds = sub_owner.getAttribute("aria-owns").split(/ +/g);
113+
for (let j=0; j < sub_ownIds.length; ++j) {
114+
const ownedNode = doc.getElementById(sub_ownIds[j]);
115+
if (ownedNode)
116+
ownedNodes.push(ownedNode);
117+
}
118+
}
119+
if (ownedNodes.length === 0) {
120+
CacheUtil.setCache(owned, "aria-owned", owner);
121+
continue;
122+
}
123+
// check if any aria-owns points to the element itself or any of it's parent
124+
let parent : Element = owner;
125+
let circular = false;
126+
while (parent !== null) {
127+
const found = ownedNodes.some(item => DOMUtil.sameNode(parent, item));
128+
if (!found)
129+
parent = DOMWalker.parentElement(parent);
130+
else {
131+
circular = true;
132+
break;
133+
}
134+
}
135+
if (!circular)
136+
CacheUtil.setCache(owned, "aria-owned", owner);
100137
}
101138
}
102139
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
4+
<head>
5+
<title>Sandbox</title>
6+
<meta charset="UTF-8" />
7+
</head>
8+
9+
<body>
10+
<div class="mm-panels">
11+
<div id="mm-1" class="mm-panel mm-panel_opened">
12+
<ul class="mm-listview">
13+
<li class="mm-listitem"><a href="#mm-2" aria-owns="mm-2">Open submenu</a>
14+
<li class="mm-listitem"><a href="#mm-3" aria-owns="mm-3">Open Another submenu</a>
15+
</li>
16+
</ul>
17+
</div>
18+
<div id="mm-3">
19+
<div class="mm-navbar"><a href="#mm-1" aria-owns="mm-1">Close submenu</a>
20+
</div>
21+
</div>
22+
</div>
23+
</body>
24+
<script>
25+
UnitTest = {
26+
ruleIds: ["aria_descendant_valid"],
27+
results: [
28+
29+
]
30+
}
31+
</script>
32+
</body>
33+
34+
</html>

0 commit comments

Comments
 (0)