Skip to content

Commit 18de8a1

Browse files
authored
fix(ui5-checkbox): add aria-hidden attribute to icon (#3511)
The role presentation on the icon SVG is ignored in some cases: *The element is focusable, e.g. it is natively focusable like an HTML link or input, or it has a tabindex attribute. *The element has any of the twenty-one global ARIA states and properties, e.g., aria-label. With this change we introduce ariaHidden property on ui5-icon to be able to completly hide it from accessibility tree mapping. Also, change the default value of effectiveAccessibleName to undefined as a value of "" will still set the aria-label attribute and the presentation role will be ignroed. Fixes #3433
1 parent c7e6f07 commit 18de8a1

File tree

7 files changed

+41
-1
lines changed

7 files changed

+41
-1
lines changed

packages/main/src/CheckBox.hbs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
>
1616
<div id="{{_id}}-CbBg" class="ui5-checkbox-inner">
1717
{{#if isCompletelyChecked}}
18-
<ui5-icon name="accept" class="ui5-checkbox-icon"></ui5-icon>
18+
<ui5-icon aria-hidden="true" name="accept" class="ui5-checkbox-icon"></ui5-icon>
1919
{{/if}}
2020

2121
<input
@@ -24,6 +24,7 @@
2424
?checked="{{checked}}"
2525
?readonly="{{readonly}}"
2626
?disabled="{{disabled}}"
27+
tabindex="-1"
2728
aria-hidden="true"
2829
data-sap-no-tab-ref
2930
/>

packages/main/src/Icon.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
focusable="false"
88
preserveAspectRatio="xMidYMid meet"
99
aria-label="{{effectiveAccessibleName}}"
10+
aria-hidden={{effectiveAriaHidden}}
1011
xmlns="http://www.w3.org/2000/svg"
1112
@focusin={{_onfocusin}}
1213
@focusout={{_onfocusout}}

packages/main/src/Icon.js

+18
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ const metadata = {
9595
type: String,
9696
},
9797

98+
/**
99+
* Defines the aria hidden state of the component.
100+
* @private
101+
* @since 1.0.0-rc.15
102+
*/
103+
ariaHidden: {
104+
type: String,
105+
},
106+
98107
/**
99108
* @private
100109
*/
@@ -130,6 +139,7 @@ const metadata = {
130139
*/
131140
effectiveAccessibleName: {
132141
type: String,
142+
defaultValue: undefined,
133143
noAttribute: true,
134144
},
135145
},
@@ -257,6 +267,14 @@ class Icon extends UI5Element {
257267
return this.effectiveDir;
258268
}
259269

270+
get effectiveAriaHidden() {
271+
if (this.ariaHidden === "") {
272+
return;
273+
}
274+
275+
return this.ariaHidden;
276+
}
277+
260278
get tabIndex() {
261279
return this.interactive ? "0" : "-1";
262280
}

packages/main/test/pages/CheckBox.html

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
<ui5-checkbox value-state="Success" text="Long long long text" indeterminate checked></ui5-checkbox>
4848
<ui5-checkbox value-state="Information" text="Long long long text" indeterminate checked></ui5-checkbox>
4949

50+
<br />
51+
<ui5-checkbox id="checkboxChecked" checked></ui5-checkbox>
52+
5053
<script>
5154
var hcb = false;
5255
var input = document.querySelector("#field");

packages/main/test/pages/Icon.html

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<ui5-icon name="add-employee" class="icon-red icon-small"></ui5-icon>
3838
<ui5-icon show-tooltip name="message-error"></ui5-icon>
3939

40+
<h3>Icon with aria-hidden="true"</h3>
41+
<ui5-icon id="araHiddenIcon" name="add-employee" aria-hidden="true" class="icon-red icon-small"></ui5-icon>
42+
4043
<h3>Interactive Icon</h3>
4144
<ui5-icon
4245
id="myInteractiveIcon"

packages/main/test/specs/CheckBox.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,10 @@ describe("CheckBox general interaction", () => {
5454
assert.strictEqual(defaultCb.getAttribute("aria-label"), null, "aria-label is not set");
5555
assert.strictEqual(accCheckBox.getAttribute("aria-label"), EXPECTED_ARIA_LABEL, "aria-label is set");
5656
});
57+
58+
it("tests ui5-icon", () => {
59+
const checkboxChecked = browser.$("#checkboxChecked").shadow$(".ui5-checkbox-icon");
60+
61+
assert.strictEqual(checkboxChecked.getAttribute("aria-hidden"), "true", "aria-hidden is set");
62+
});
5763
});

packages/main/test/specs/Icon.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,12 @@ describe("Icon general interaction", () => {
5656
icon.click();
5757
assert.strictEqual(input.getAttribute("value"), "1", "Mouse click throws event");
5858
});
59+
60+
it("Tests the accessibility attributes", () => {
61+
const iconRoot = browser.$("#myIcon").shadow$(".ui5-icon-root");
62+
const ariaHiddenIconRoot = browser.$("#araHiddenIcon").shadow$(".ui5-icon-root");
63+
64+
assert.strictEqual(iconRoot.getAttribute("aria-hidden"), null, "The aria-hidden attribute is not set");
65+
assert.strictEqual(ariaHiddenIconRoot.getAttribute("aria-hidden"), "true", "The ariaHidden property works");
66+
});
5967
});

0 commit comments

Comments
 (0)