Skip to content

Commit 9943ee7

Browse files
author
GerganaKremenska
authored
feat(ui5-dialog): labeling of header slots is now possible (#3155)
When Dialog's header slot is used, developers now would be able to use newly added accessible-name attribute to label the dialog properly. (If the header slot is not used, the Dialog labels the internally created header as previous.) Fixes: #2838
1 parent 927abf6 commit 9943ee7

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

packages/main/src/Dialog.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const metadata = {
2020
slots: /** @lends sap.ui.webcomponents.main.Dialog.prototype */ {
2121
/**
2222
* Defines the header HTML Element.
23+
* <br><br>
24+
* <b>Note:</b> If <code>header</code> slot is provided, the labelling of the dialog is a responsibility of the application developer.
25+
* <code>accessibleName</code> should be used.
2326
*
2427
* @type {HTMLElement[]}
2528
* @slot
@@ -54,6 +57,20 @@ const metadata = {
5457
type: String,
5558
},
5659

60+
/**
61+
* Defines the accessible name of the dialog when <code>header</code> slot is provided.
62+
* <br><br>
63+
*
64+
* <b>Note:</b> If <code>aria-label</code> is provided, <code>accessibleName</code> will be ignored.
65+
66+
* @type {string}
67+
* @defaultvalue ""
68+
* @public
69+
*/
70+
accessibleName: {
71+
type: String,
72+
},
73+
5774
/**
5875
* Determines whether the <code>ui5-dialog</code> should be stretched to fullscreen.
5976
* <br><br>
@@ -205,7 +222,22 @@ class Dialog extends Popup {
205222
}
206223

207224
get _ariaLabelledBy() { // Required by Popup.js
208-
return (this.ariaLabel || this.header.length) ? undefined : "ui5-popup-header-text";
225+
let ariaLabelledById;
226+
227+
if (this.headerText !== "" && !this.ariaLabel) {
228+
ariaLabelledById = "ui5-popup-header-text";
229+
}
230+
231+
return ariaLabelledById;
232+
}
233+
234+
get _ariaLabel() {
235+
let ariaLabel;
236+
237+
if (this.header.length > 0 && !!this.accessibleName) {
238+
ariaLabel = this.accessibleName;
239+
}
240+
return this.ariaLabel ? this.ariaLabel : ariaLabel;
209241
}
210242

211243
get _ariaModal() { // Required by Popup.js

packages/main/test/pages/Dialog.html

+12-10
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@
114114
</ui5-dialog>
115115

116116

117-
<ui5-dialog id="dialog" stretch>
117+
<ui5-dialog id="dialog" accessible-name="Resizable" stretch>
118118
<div slot="header">
119119
<ui5-button id="header-button">focus stop</ui5-button>
120+
<ui5-title id="tt" level="H2">Resizable</ui5-title>
121+
120122
</div>
121123

122124
<div style="padding: 1rem;text-align: center;">
123-
<ui5-title level="H2">Hello World!</ui5-title>
125+
<ui5-title level="H3">Hello World!</ui5-title>
124126
</div>
125127

126128
<ui5-select id="mySelect">
@@ -132,7 +134,7 @@
132134
</ui5-textarea>
133135

134136
<div style="padding: 1rem;text-align: center;">
135-
<ui5-title level="H2">Hello World!</ui5-title>
137+
<ui5-title level="H3">Hello World!</ui5-title>
136138
</div>
137139

138140
<ui5-select>
@@ -144,7 +146,7 @@
144146
</ui5-textarea>
145147

146148
<div style="padding: 1rem;text-align: center;">
147-
<ui5-title level="H2">Hello World!</ui5-title>
149+
<ui5-title level="H3">Hello World!</ui5-title>
148150
</div>
149151

150152
<ui5-select>
@@ -157,7 +159,7 @@
157159

158160

159161
<div style="padding: 1rem;text-align: center;">
160-
<ui5-title level="H2">Hello World!</ui5-title>
162+
<ui5-title level="H3">Hello World!</ui5-title>
161163
</div>
162164

163165
<ui5-select>
@@ -183,7 +185,7 @@
183185

184186

185187
<div style="padding: 1rem;text-align: center;">
186-
<ui5-title level="H2">Hello World!</ui5-title>
188+
<ui5-title level="H3">Hello World!</ui5-title>
187189
</div>
188190

189191
<ui5-select>
@@ -196,7 +198,7 @@
196198

197199

198200
<div style="padding: 1rem;text-align: center;">
199-
<ui5-title level="H2">Hello World!</ui5-title>
201+
<ui5-title level="H3">Hello World!</ui5-title>
200202
</div>
201203

202204
<ui5-select>
@@ -271,8 +273,8 @@
271273
</div>
272274
</ui5-dialog>
273275

274-
<ui5-dialog id="draggable-dialog" draggable>
275-
<div slot="header" style="flex: 1 0 0; height: 2.5rem;">Draggable dialog</div>
276+
<ui5-dialog id="draggable-dialog" accessible-name="Draggable" draggable>
277+
<div id="tlt" slot="header" style="flex: 1 0 0; height: 2.5rem;">Draggable dialog</div>
276278

277279
<p>Move this dialog around the screen by dragging it by its header.</p>
278280
<p>This feature available only on Desktop.</p>
@@ -430,4 +432,4 @@
430432
</script>
431433
</body>
432434

433-
</html>
435+
</html>

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

+11
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,15 @@ describe("Acc", () => {
159159
assert.ok(!dialog.shadow$(".ui5-popup-root").getAttribute("aria-labelledby"), "dialog does not have aria-labelledby.");
160160
assert.ok(dialog.shadow$(".ui5-popup-root").getAttribute("aria-label").length, "dialog has aria-label.");
161161
});
162+
163+
it("tests aria-labelledby for slot header", () => {
164+
const openDraggableDialog = browser.$("#draggable-open");
165+
openDraggableDialog.click();
166+
167+
const dialog = browser.$("#draggable-dialog");
168+
const accName = "Draggable" ;
169+
170+
assert.strictEqual(dialog.getAttribute("accessible-name"), accName, "dialog has correct attribute set");
171+
assert.strictEqual(dialog.shadow$(".ui5-popup-root").getAttribute("aria-label"), accName, "dialog has aria-label.");
172+
});
162173
});

0 commit comments

Comments
 (0)