Skip to content

Commit f0f8964

Browse files
authored
fix(ui5-button): make aria-label work for ui5-button (#1445)
1 parent 4e00e55 commit f0f8964

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

packages/base/src/util/isValidPropertyName.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
// Note: disabled is present in IE so we explicitly allow it here.
2+
// Others, such as ariaLabel, we explicitly override, so valid too
3+
const whitelist = ["disabled", "ariaLabel"];
4+
15
/**
26
* Checks whether a property name is valid (does not collide with existing DOM API properties)
3-
* Note: disabled is present in IE so we explicitly allow it here.
47
*
58
* @param name
69
* @returns {boolean}
710
*/
811
const isValidPropertyName = name => {
9-
if (name === "disabled") {
12+
if (whitelist.includes(name)) {
1013
return true;
1114
}
1215
const classes = [

packages/main/src/Button.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
tabindex={{tabIndexValue}}
1616
aria-expanded="{{accInfo.ariaExpanded}}"
1717
aria-controls="{{accInfo.ariaControls}}"
18-
aria-label="{{ariaLabelledByText}}"
18+
aria-label="{{ariaLabelText}}"
1919
title="{{accInfo.title}}"
2020
part="button"
2121
>

packages/main/src/Button.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ const metadata = {
129129
type: Boolean,
130130
},
131131

132+
/**
133+
* Defines the aria-label attribute for the button
134+
* @type {String}
135+
* @defaultvalue: ""
136+
* @private
137+
* @since 1.0.0-rc.7
138+
*/
139+
ariaLabel: {
140+
type: String,
141+
defaultValue: undefined,
142+
},
143+
132144
/**
133145
* Receives id(or many ids) of the elements that label the button
134146
* @type {String}
@@ -328,8 +340,12 @@ class Button extends UI5Element {
328340
};
329341
}
330342

331-
get ariaLabelledByText() {
343+
get ariaLabelText() {
332344
if (!this.ariaLabelledby) {
345+
if (this.ariaLabel) {
346+
return this.ariaLabel;
347+
}
348+
333349
return undefined;
334350
}
335351

packages/main/test/pages/Button.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,24 @@
6262
<br/>
6363
<br/>
6464

65-
<ui5-button icon="employee">Action Bar Button</ui5-button>
66-
<ui5-button icon="download"></ui5-button>
65+
<ui5-button icon="download" aria-label="Download application"></ui5-button>
66+
<ui5-button icon="employee" aria-label="Download book">Action Bar Button</ui5-button>
6767
<ui5-button icon="download"></ui5-button>
6868

6969
<br />
7070
<br />
7171

7272
<ui5-label id="1download-text">Download Application</ui5-label>
7373
<ui5-label id="download-text2">From This Button</ui5-label>
74+
75+
<ui5-button icon="employee" aria-label="Help me">Action Bar Button</ui5-button>
76+
<ui5-button icon="download" aria-label="Help me" aria-labelledby="1download-text"></ui5-button>
77+
7478
<ui5-button icon="employee" aria-labelledby="1download-text download-text2">Action Bar Button</ui5-button>
7579
<ui5-button icon="download" aria-labelledby="1download-text"></ui5-button>
7680

7781

82+
7883
<br/>
7984
<br/>
8085
<br/>

0 commit comments

Comments
 (0)