Skip to content

Commit 5d62888

Browse files
dobrinyonkovilhan007
authored andcommitted
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 9c997fe commit 5d62888

File tree

7 files changed

+41
-1
lines changed

7 files changed

+41
-1
lines changed

packages/main/src/CheckBox.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
>
1616
<div id="{{_id}}-CbBg" class="ui5-checkbox-inner">
1717
{{#if checked}}
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 18 additions & 0 deletions
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
},
@@ -247,6 +257,14 @@ class Icon extends UI5Element {
247257
return this.effectiveDir;
248258
}
249259

260+
get effectiveAriaHidden() {
261+
if (this.ariaHidden === "") {
262+
return;
263+
}
264+
265+
return this.ariaHidden;
266+
}
267+
250268
get tabIndex() {
251269
return this.interactive ? "0" : "-1";
252270
}

packages/main/test/pages/CheckBox.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
<ui5-title>ACC test - aria-label</ui5-title>
3737
<ui5-checkbox id="accCb" aria-label="Hello world"></ui5-checkbox>
3838

39+
<br />
40+
<ui5-checkbox id="checkboxChecked" checked></ui5-checkbox>
41+
3942
<script>
4043
var hcb = false;
4144
var input = document.querySelector("#field");

packages/main/test/pages/Icon.html

Lines changed: 3 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,10 @@ describe("CheckBox general interaction", () => {
5151
assert.strictEqual(defaultCb.getAttribute("aria-label"), null, "aria-label is not set");
5252
assert.strictEqual(accCheckBox.getAttribute("aria-label"), EXPECTED_ARIA_LABEL, "aria-label is set");
5353
});
54+
55+
it("tests ui5-icon", () => {
56+
const checkboxChecked = browser.$("#checkboxChecked").shadow$(".ui5-checkbox-icon");
57+
58+
assert.strictEqual(checkboxChecked.getAttribute("aria-hidden"), "true", "aria-hidden is set");
59+
});
5460
});

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,12 @@ describe("Icon general interaction", () => {
4949
icon.click();
5050
assert.strictEqual(input.getAttribute("value"), "1", "Mouse click throws event");
5151
});
52+
53+
it("Tests the accessibility attributes", () => {
54+
const iconRoot = browser.$("#myIcon").shadow$(".ui5-icon-root");
55+
const ariaHiddenIconRoot = browser.$("#araHiddenIcon").shadow$(".ui5-icon-root");
56+
57+
assert.strictEqual(iconRoot.getAttribute("aria-hidden"), null, "The aria-hidden attribute is not set");
58+
assert.strictEqual(ariaHiddenIconRoot.getAttribute("aria-hidden"), "true", "The ariaHidden property works");
59+
});
5260
});

0 commit comments

Comments
 (0)