Skip to content

Commit 69d8ee4

Browse files
authored
feat(ui5-popup): add support for aria-label (#1898)
1 parent 31f4b1a commit 69d8ee4

File tree

8 files changed

+67
-6
lines changed

8 files changed

+67
-6
lines changed

packages/main/src/Dialog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class Dialog extends Popup {
127127
}
128128

129129
get _ariaLabelledBy() { // Required by Popup.js
130-
return "ui5-popup-header";
130+
return this.ariaLabel ? undefined : "ui5-popup-header";
131131
}
132132

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

packages/main/src/Input.js

+2
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ const metadata = {
272272
},
273273

274274
/**
275+
* Defines the aria-label attribute for the input
276+
*
275277
* @type {String}
276278
* @since 1.0.0-rc.8
277279
* @private

packages/main/src/Popover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ class Popover extends Popup {
599599
}
600600

601601
get _ariaLabelledBy() { // Required by Popup.js
602-
return "ui5-popup-header";
602+
return this.ariaLabel ? undefined : "ui5-popup-header";
603603
}
604604

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

packages/main/src/Popup.hbs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
<section style="{{styles.root}}" class="{{classes.root}}" role="dialog" aria-modal="{{_ariaModal}}" aria-labelledby="{{_ariaLabelledBy}}">
1+
<section
2+
style="{{styles.root}}"
3+
class="{{classes.root}}"
4+
role="dialog"
5+
aria-modal="{{_ariaModal}}"
6+
aria-label="{{_ariaLabel}}"
7+
aria-labelledby="{{_ariaLabelledBy}}"
8+
>
29

310
<span class="first-fe" data-ui5-focus-trap tabindex="0" @focusin={{forwardToLast}}></span>
411

packages/main/src/Popup.js

+21
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ const metadata = {
4848
type: Boolean,
4949
},
5050

51+
/**
52+
* Defines the aria-label attribute for the popup
53+
*
54+
* @type {String}
55+
* @defaultvalue: ""
56+
* @private
57+
* @since 1.0.0-rc.8
58+
*/
59+
ariaLabel: {
60+
type: String,
61+
defaultValue: undefined,
62+
},
63+
5164
/**
5265
* @private
5366
*/
@@ -390,6 +403,14 @@ class Popup extends UI5Element {
390403
*/
391404
get _ariaModal() {} // eslint-disable-line
392405

406+
/**
407+
* Ensures ariaLabel is never null or empty string
408+
* @returns {String|undefined}
409+
* @protected
410+
*/
411+
get _ariaLabel() {
412+
return this.ariaLabel || undefined;
413+
}
393414

394415
get styles() {
395416
return {

packages/main/test/pages/Popover.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
<ui5-button id="btn">Click me !</ui5-button>
6262

63-
<ui5-popover header-text="My Heading" id="pop" style="width: 300px" placement-type="Top">
63+
<ui5-popover header-text="My Heading" id="pop" style="width: 300px" placement-type="Top" aria-label="This popover is important">
6464
<div slot="header">
6565
<ui5-button id="first-focusable">I am in the header</ui5-button>
6666
</div>
@@ -355,4 +355,4 @@
355355
</script>
356356
</body>
357357

358-
</html>
358+
</html>

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe("Dialog general interaction", () => {
1010
btnOpenDialog.click();
1111

1212
const dialog = browser.$("#dialog");
13-
13+
1414
assert.ok(dialog.isDisplayedInViewport(), "Dialog is opened.");
1515

1616
btnCloseDialog.click();
@@ -32,3 +32,19 @@ describe("Dialog general interaction", () => {
3232
assert.ok(popoverZIndex > dialogZIndex, "Popover is above dialog.");
3333
});
3434
});
35+
36+
37+
describe("Acc", () => {
38+
browser.url("http://localhost:8080/test-resources/pages/Dialog.html");
39+
40+
it("tests aria-labelledby and aria-label", () => {
41+
const dialog = browser.$("ui5-dialog");
42+
dialog.removeAttribute("aria-label");
43+
assert.ok(dialog.shadow$(".ui5-popup-root").getAttribute("aria-labelledby").length, "dialog has aria-labelledby.");
44+
assert.ok(!dialog.shadow$(".ui5-popup-root").getAttribute("aria-label"), "dialog does not have aria-label.");
45+
46+
dialog.setAttribute("aria-label", "text");
47+
assert.ok(!dialog.shadow$(".ui5-popup-root").getAttribute("aria-labelledby"), "dialog does not have aria-labelledby.");
48+
assert.ok(dialog.shadow$(".ui5-popup-root").getAttribute("aria-label").length, "dialog has aria-label.");
49+
});
50+
});

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

+15
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,18 @@ describe("Popover general interaction", () => {
180180
assert.ok(ff.getProperty("focused"), "The first focusable element is focused.");
181181
});
182182
});
183+
184+
describe("Acc", () => {
185+
browser.url("http://localhost:8080/test-resources/pages/Popover.html");
186+
187+
it("tests aria-labelledby and aria-label", () => {
188+
const popover = browser.$("ui5-popover");
189+
popover.removeAttribute("aria-label");
190+
assert.ok(popover.shadow$(".ui5-popup-root").getAttribute("aria-labelledby").length, "Popover has aria-labelledby.");
191+
assert.ok(!popover.shadow$(".ui5-popup-root").getAttribute("aria-label"), "Popover does not have aria-label.");
192+
193+
popover.setAttribute("aria-label", "text");
194+
assert.ok(!popover.shadow$(".ui5-popup-root").getAttribute("aria-labelledby"), "Popover does not have aria-labelledby.");
195+
assert.ok(popover.shadow$(".ui5-popup-root").getAttribute("aria-label").length, "Popover has aria-label.");
196+
});
197+
});

0 commit comments

Comments
 (0)