Skip to content

Commit 786005b

Browse files
update the rule and add a test case #dev-2085 (#2180)
Co-authored-by: Phill Jenkins <pjenkins@us.ibm.com>
1 parent a7e92a1 commit 786005b

File tree

2 files changed

+109
-2
lines changed

2 files changed

+109
-2
lines changed

accessibility-checker-engine/src/v4/util/AccNameUtil.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,15 @@ export class AccNameUtil {
144144
let pair = AccNameUtil.computeAccessibleName(image);
145145
if (pair && pair.name && pair.name.trim().length > 0)
146146
return pair;
147-
}
147+
}
148+
149+
// for a button with a svg image
150+
const svg = elem.querySelector('svg');
151+
if (svg && !VisUtil.isNodeHiddenFromAT(svg) && !VisUtil.isNodePresentational(svg)) {
152+
let pair = AccNameUtil.computeAccessibleNameForSVGElement(svg);
153+
if (pair && pair.name && pair.name.trim().length > 0)
154+
return pair;
155+
}
148156
}
149157

150158
// fieldset
@@ -397,7 +405,7 @@ export class AccNameUtil {
397405
const contentElem = elem.ownerDocument.defaultView.getComputedStyle(elem,type);
398406
if (contentElem) {
399407
let content = contentElem.content;
400-
if (content && content !== "none") {
408+
if (content && content !== "none" && content !== "no" && content !== "normal") {
401409
content = content.replace(/^"/,"").replace(/"$/,"");
402410
if (content.trim().length > 0)
403411
return {"name": CommonUtil.truncateText(content), "nameFrom": "css-"+type};
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<title>Input with image child</title>
9+
10+
</head>
11+
12+
<body>
13+
14+
<hr style="margin: 20px;">
15+
16+
<button aria-hidden="true" tabindex="-1" aria-label="Scroll right"
17+
class="cds--tab--overflow-nav-button cds--tab--overflow-nav-button--next cds--tab--overflow-nav-button--hidden"
18+
type="button"><svg focusable="false" preserveAspectRatio="xMidYMid meet" fill="currentColor" width="16" height="16"
19+
viewBox="0 0 16 16" aria-hidden="true" xmlns="http://www.w3.org/2000/svg">
20+
<path d="M11 8L6 13 5.3 12.3 9.6 8 5.3 3.7 6 3z"></path>
21+
</svg>
22+
</button>
23+
24+
<hr style="margin: 20px;">
25+
<button type="button">
26+
<svg focusable="false">
27+
<defs><style>.cls-1{fill:none;}</style></defs>
28+
<rect class="cls-1" width="32" height="32"></rect>
29+
<title>text</title>
30+
</svg>
31+
</button>
32+
33+
<hr style="margin: 20px;">
34+
<button type="button">
35+
<svg focusable="false" aria-label="svg image">
36+
<defs><style>.cls-1{fill:none;}</style></defs>
37+
<rect class="cls-1" width="32" height="32"></rect>
38+
</svg>
39+
</button>
40+
41+
<hr style="margin: 50px;">
42+
</body>
43+
<script>
44+
UnitTest = {
45+
ruleIds: ["input_label_visible"],
46+
results: [
47+
{
48+
"ruleId": "input_label_visible",
49+
"value": [
50+
"INFORMATION",
51+
"POTENTIAL"
52+
],
53+
"path": {
54+
"dom": "/html[1]/body[1]/button[1]",
55+
"aria": "/document[1]/button[1]"
56+
},
57+
"reasonId": "potential_no_label",
58+
"message": "The input element does not have an associated visible label",
59+
"messageArgs": [],
60+
"apiArgs": [],
61+
"category": "Accessibility"
62+
},
63+
{
64+
"ruleId": "input_label_visible",
65+
"value": [
66+
"INFORMATION",
67+
"POTENTIAL"
68+
],
69+
"path": {
70+
"dom": "/html[1]/body[1]/button[2]",
71+
"aria": "/document[1]/button[2]"
72+
},
73+
"reasonId": "potential_no_label",
74+
"message": "The input element does not have an associated visible label",
75+
"messageArgs": [],
76+
"apiArgs": [],
77+
"category": "Accessibility"
78+
},
79+
{
80+
"ruleId": "input_label_visible",
81+
"value": [
82+
"INFORMATION",
83+
"POTENTIAL"
84+
],
85+
"path": {
86+
"dom": "/html[1]/body[1]/button[3]",
87+
"aria": "/document[1]/button[3]"
88+
},
89+
"reasonId": "potential_no_label",
90+
"message": "The input element does not have an associated visible label",
91+
"messageArgs": [],
92+
"apiArgs": [],
93+
"category": "Accessibility"
94+
}
95+
]
96+
};
97+
</script>
98+
99+
</html>

0 commit comments

Comments
 (0)