Skip to content

Commit 9594a36

Browse files
author
GerganaKremenska
committed
introduce labeling for header slot in Dialog
1 parent 4003f8e commit 9594a36

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

packages/main/src/Dialog.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ const metadata = {
5454
type: String,
5555
},
5656

57+
/**
58+
* Defines the aria-labelledBy of the dialog when <code>header</code> slot is provided.
59+
* <br><br>
60+
* <b>Note:</b> If <code>header</code> slot is provided, the <code>accessibleNameId</code> should be provided by the developer.
61+
* <b>Note:</b> Do not use <code>accessibleNameId</code> if there is a shadow boundary,
62+
* referencing IDs inside the component is impossible. In this case use <code>ariaLabel</code>.
63+
*
64+
* @type {string}
65+
* @defaultvalue ""
66+
* @public
67+
*/
68+
accessibleNameId: {
69+
type: String,
70+
},
71+
5772
/**
5873
* Determines whether the <code>ui5-dialog</code> should be stretched to fullscreen.
5974
* <br><br>
@@ -205,7 +220,14 @@ class Dialog extends Popup {
205220
}
206221

207222
get _ariaLabelledBy() { // Required by Popup.js
208-
return (this.ariaLabel || this.header.length) ? undefined : "ui5-popup-header-text";
223+
let ariaLabelledById;
224+
225+
if (this.headerText !== "" && !this.ariaLabel) {
226+
ariaLabelledById = "ui5-popup-header-text";
227+
} else if (this.accessibleNameId.length !== 0) {
228+
ariaLabelledById = this.accessibleNameId;
229+
}
230+
return ariaLabelledById;
209231
}
210232

211233
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" aria-label="Hello UI5!" stretch>
118118
<div slot="header">
119119
<ui5-button id="header-button">focus stop</ui5-button>
120+
<ui5-title level="H2">Hello UI5!</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-id="tlt" 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

+10
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,14 @@ 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+
169+
assert.strictEqual(dialog.getAttribute("accessible-name-id"), "tlt", "dialog has correct attribute set");
170+
assert.strictEqual(dialog.shadow$(".ui5-popup-root").getAttribute("aria-labelledby"), "tlt", "dialog has aria-labelledby.");
171+
});
162172
});

0 commit comments

Comments
 (0)