Skip to content

Commit df9e4e9

Browse files
authored
fix(ui5-button): apply aria-expanded to inner button tag (#1781)
1 parent a04f483 commit df9e4e9

File tree

5 files changed

+69
-40
lines changed

5 files changed

+69
-40
lines changed

packages/base/src/util/isValidPropertyName.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Note: disabled is present in IE so we explicitly allow it here.
22
// Others, such as ariaLabel, we explicitly override, so valid too
3-
const whitelist = ["disabled", "ariaLabel"];
3+
const whitelist = [
4+
"disabled",
5+
"ariaLabel",
6+
"ariaExpanded",
7+
];
48

59
/**
610
* Checks whether a property name is valid (does not collide with existing DOM API properties)

packages/main/src/Button.hbs

+36-36
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
<button
2-
type="button"
3-
class="ui5-button-root"
4-
?disabled="{{disabled}}"
5-
data-sap-focus-ref
6-
{{> ariaPressed}}
7-
dir="{{effectiveDir}}"
8-
@focusout={{_onfocusout}}
9-
@focusin={{_onfocusin}}
10-
@click={{_onclick}}
11-
@mousedown={{_onmousedown}}
12-
@mouseup={{_onmouseup}}
13-
@keydown={{_onkeydown}}
14-
@keyup={{_onkeyup}}
15-
tabindex={{tabIndexValue}}
16-
aria-expanded="{{accInfo.ariaExpanded}}"
17-
aria-controls="{{accInfo.ariaControls}}"
18-
aria-haspopup="{{accInfo.ariaHaspopup}}"
19-
aria-label="{{ariaLabelText}}"
20-
title="{{accInfo.title}}"
21-
part="button"
22-
>
23-
{{#if icon}}
24-
<ui5-icon
25-
class="ui5-button-icon"
26-
name="{{icon}}"
27-
show-tooltip={{iconOnly}}
28-
></ui5-icon>
29-
{{/if}}
2+
type="button"
3+
class="ui5-button-root"
4+
?disabled="{{disabled}}"
5+
data-sap-focus-ref
6+
{{> ariaPressed}}
7+
dir="{{effectiveDir}}"
8+
@focusout={{_onfocusout}}
9+
@focusin={{_onfocusin}}
10+
@click={{_onclick}}
11+
@mousedown={{_onmousedown}}
12+
@mouseup={{_onmouseup}}
13+
@keydown={{_onkeydown}}
14+
@keyup={{_onkeyup}}
15+
tabindex={{tabIndexValue}}
16+
aria-expanded="{{accInfo.ariaExpanded}}"
17+
aria-controls="{{accInfo.ariaControls}}"
18+
aria-haspopup="{{accInfo.ariaHaspopup}}"
19+
aria-label="{{ariaLabelText}}"
20+
title="{{accInfo.title}}"
21+
part="button"
22+
>
23+
{{#if icon}}
24+
<ui5-icon
25+
class="ui5-button-icon"
26+
name="{{icon}}"
27+
show-tooltip={{iconOnly}}
28+
></ui5-icon>
29+
{{/if}}
3030

31-
<span id="{{_id}}-content" class="ui5-button-text">
32-
<bdi>
33-
<slot></slot>
34-
</bdi>
35-
</span>
31+
<span id="{{_id}}-content" class="ui5-button-text">
32+
<bdi>
33+
<slot></slot>
34+
</bdi>
35+
</span>
3636

37-
{{#if hasButtonType}}
38-
<span class="ui5-hidden-text">{{buttonTypeText}}</span>
39-
{{/if}}
37+
{{#if hasButtonType}}
38+
<span class="ui5-hidden-text">{{buttonTypeText}}</span>
39+
{{/if}}
4040
</button>
4141

4242
{{#*inline "ariaPressed"}}{{/inline}}

packages/main/src/Button.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ const metadata = {
153153
defaultValue: "",
154154
},
155155

156+
/**
157+
* @type {String}
158+
* @defaultvalue ""
159+
* @public
160+
* @since 1.0.0-rc.8
161+
*/
162+
ariaExpanded: {
163+
type: String,
164+
},
165+
156166
/**
157167
* Indicates if the element if focusable
158168
* @private
@@ -340,7 +350,7 @@ class Button extends UI5Element {
340350

341351
get accInfo() {
342352
return {
343-
"ariaExpanded": this._buttonAccInfo && this._buttonAccInfo.ariaExpanded,
353+
"ariaExpanded": this.ariaExpanded || (this._buttonAccInfo && this._buttonAccInfo.ariaExpanded),
344354
"ariaControls": this._buttonAccInfo && this._buttonAccInfo.ariaControls,
345355
"ariaHaspopup": this._buttonAccInfo && this._buttonAccInfo.ariaHaspopup,
346356
"title": this._buttonAccInfo && this._buttonAccInfo.title,

packages/main/test/pages/Button.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<ui5-icon name="invalid_name"></ui5-icon>
4242
<ui5-button design="Emphasized" icon="invalid_name">Press</ui5-button>
4343

44-
<ui5-button id="button1" design="Emphasized">Action Bar Button</ui5-button>
44+
<ui5-button id="button1" design="Emphasized" aria-expanded="true">Action Bar Button</ui5-button>
4545
<ui5-button style="height: auto">Primary <br> button</ui5-button>
4646
<ui5-button style="height: auto" design="Transparent">Secondary <span style="color:red;">button</span></ui5-button>
4747
<ui5-button disabled id="button-disabled">Inactive</ui5-button>

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("Button general interaction", () => {
1616

1717
button.setAttribute("icon", "add");
1818
assert.strictEqual(button.shadow$$("ui5-icon").length, 1, "icon is present");
19-
19+
2020
button.setAttribute("icon", "");
2121
assert.strictEqual(button.shadow$$("ui5-icon").length, 0, "icon is not present");
2222
});
@@ -78,4 +78,19 @@ describe("Button general interaction", () => {
7878

7979
assert.strictEqual(field.getProperty("value"), "6", "click should be called 6 times");
8080
});
81+
82+
it("setting aria-expanded on the host is reflected on the button tag", () => {
83+
const button = browser.$("#button1");
84+
const innerButton = button.shadow$("button");
85+
86+
assert.strictEqual(innerButton.getAttribute("aria-expanded"), "true", "Attribute is reflected");
87+
88+
button.setAttribute("aria-expanded", "false");
89+
90+
assert.strictEqual(innerButton.getAttribute("aria-expanded"), "false", "Attribute is reflected");
91+
92+
button.removeAttribute("aria-expanded");
93+
94+
assert.strictEqual(innerButton.getAttribute("aria-expanded"), null, "Attribute is reflected");
95+
})
8196
});

0 commit comments

Comments
 (0)