Skip to content

Commit b133468

Browse files
ivoplashkovilhan007
authored andcommitted
feat(ui5-panel): implement accessibility (#864)
1 parent 07a44cf commit b133468

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
lines changed

packages/main/src/Button.hbs

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
@click={{_onclick}}
1111
@mousedown={{_onmousedown}}
1212
tabindex={{tabIndexValue}}
13+
aria-expanded="{{accInfo.ariaExpanded}}"
14+
aria-controls="{{accInfo.ariaControls}}"
15+
title="{{accInfo.title}}"
1316
>
1417
{{#if icon}}
1518
<ui5-icon

packages/main/src/Button.js

+8
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ class Button extends UI5Element {
295295
return this.design !== ButtonDesign.Default && this.design !== ButtonDesign.Transparent;
296296
}
297297

298+
get accInfo() {
299+
return {
300+
"ariaExpanded": this._buttonAccInfo && this._buttonAccInfo.ariaExpanded,
301+
"ariaControls": this._buttonAccInfo && this._buttonAccInfo.ariaControls,
302+
"title": this._buttonAccInfo && this._buttonAccInfo.title,
303+
};
304+
}
305+
298306
static typeTextMappings() {
299307
return {
300308
"Positive": BUTTON_ARIA_TYPE_ACCEPT,

packages/main/src/Panel.hbs

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@
44
role="{{accRole}}"
55
>
66
<!-- header: either header or h1 with header text -->
7-
<header
7+
<div
88
@click="{{_headerClick}}"
99
@keydown="{{_headerKeyDown}}"
1010
@keyup="{{_headerKeyUp}}"
1111
class="ui5-panel-header"
1212
tabindex="{{headerTabIndex}}"
13+
role="{{accInfo.role}}"
14+
aria-expanded="{{accInfo.ariaExpanded}}"
15+
aria-controls="{{accInfo.ariaControls}}"
1316
>
1417
<div
1518
class="ui5-panel-header-button-root"
1619
>
1720
<ui5-button
1821
design="Transparent"
1922
class="ui5-panel-header-button"
20-
aria-expanded="{{expanded}}"
23+
icon="sap-icon://navigation-right-arrow"
2124
?non-focusable="{{nonFocusableButton}}"
2225
@click="{{_toggleButtonClick}}"
23-
icon="sap-icon://navigation-right-arrow"
24-
title="{{toggleButtonTitle}}"
26+
._buttonAccInfo="{{accInfo.button}}"
2527
></ui5-button>
2628
</div>
2729

@@ -32,10 +34,10 @@
3234
<h1 class="ui5-panel-header-title">{{headerText}}</h1>
3335
</div>
3436
{{/if}}
35-
</header>
37+
</div>
3638

3739
<!-- content area -->
38-
<div class="ui5-panel-content" tabindex="-1" style="{{styles.content}}">
40+
<div class="ui5-panel-content" id="{{_id}}-content" tabindex="-1" style="{{styles.content}}">
3941
<slot></slot>
4042
</div>
4143
</div>

packages/main/src/Panel.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ const metadata = {
104104
_hasHeader: {
105105
type: Boolean,
106106
},
107-
108107
_header: {
109108
type: Object,
110109
},
@@ -116,6 +115,9 @@ const metadata = {
116115
type: Boolean,
117116
noAttribute: true,
118117
},
118+
_buttonAccInfo: {
119+
type: Object,
120+
},
119121
},
120122
events: {
121123

@@ -310,6 +312,19 @@ class Panel extends UI5Element {
310312
return this.accessibleRole.toLowerCase();
311313
}
312314

315+
get accInfo() {
316+
return {
317+
"button": {
318+
"ariaExpanded": this._hasHeader ? this.expanded : undefined,
319+
"ariaControls": this._hasHeader ? `${this._id}-content` : undefined,
320+
"title": this.toggleButtonTitle,
321+
},
322+
"ariaExpanded": !this._hasHeader ? this.expanded : undefined,
323+
"ariaControls": !this._hasHeader ? `${this._id}-content` : undefined,
324+
"role": !this._hasHeader ? "button" : undefined,
325+
};
326+
}
327+
313328
get headerTabIndex() {
314329
return (this.header.length || this.fixed) ? "-1" : "0";
315330
}

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

+27
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,31 @@ describe("Panel general interaction", () => {
3434

3535
assert.strictEqual(field.getProperty("value"), "3", "Press should be called 3 times");
3636
});
37+
38+
describe("Accessibility", () => {
39+
40+
it("tests whether aria attributes are set correctly with native header", () => {
41+
const header = browser.$("#panel1").shadow$(".ui5-panel-header");
42+
const button = browser.$("#panel1").shadow$(".ui5-panel-header-button");
43+
44+
assert.ok(!button.getAttribute("aria-expanded"), "aria-expanded shouldn't be set on the button");
45+
assert.ok(!button.getAttribute("aria-controls"), "aria-controls shouldn't be set on the button");
46+
assert.ok(!button.getAttribute("title"), "title shouldn't be set on the button");
47+
48+
assert.ok(header.getAttribute("aria-expanded"), "aria-expanded should be set on the header");
49+
assert.ok(header.getAttribute("aria-controls"), "aria-controls should be set on the header");
50+
});
51+
52+
it("tests whether aria attributes are set correctly in case of custom header", () => {
53+
const button = browser.$("#panel2").shadow$(".ui5-panel-header-button").shadow$(".ui5-button-root");
54+
const header = browser.$("#panel2").shadow$(".ui5-panel-header");
55+
56+
assert.ok(!header.getAttribute("aria-expanded"), "aria-expanded shouldn't be set on the header");
57+
assert.ok(!header.getAttribute("aria-controls"), "aria-controls shouldn't be set on the header");
58+
59+
assert.ok(button.getAttribute("aria-expanded"), "aria-expanded should be set on the button");
60+
assert.ok(button.getAttribute("aria-controls"), "aria-controls should be set on the button");
61+
assert.ok(button.getAttribute("title"), "title should be set on the button");
62+
});
63+
});
3764
});

0 commit comments

Comments
 (0)