Skip to content

Commit e7dd012

Browse files
authored
fix(ui5-input): don't render aria-describedby if not neccessary (#2512)
1 parent 30d9d2b commit e7dd012

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

packages/main/src/Input.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1047,16 +1047,18 @@ class Input extends UI5Element {
10471047
return this.hasValueState ? `${this._id}-valueStateDesc` : "";
10481048
}
10491049

1050+
get suggestionsCount() {
1051+
return this.showSuggestions ? `${this._id}-suggestionsCount` : "";
1052+
}
1053+
10501054
get accInfo() {
10511055
const ariaHasPopupDefault = this.showSuggestions ? "true" : undefined;
10521056
const ariaAutoCompleteDefault = this.showSuggestions ? "list" : undefined;
1053-
const ariaDescribedBy = this._inputAccInfo.ariaDescribedBy ? `${this.suggestionsTextId} ${this.valueStateTextId} ${this._id}-suggestionsCount ${this._inputAccInfo.ariaDescribedBy}`.trim() : `${this.suggestionsTextId} ${this.valueStateTextId} ${this._id}-suggestionsCount`.trim();
1057+
const ariaDescribedBy = this._inputAccInfo.ariaDescribedBy ? `${this.suggestionsTextId} ${this.valueStateTextId} ${this.suggestionsCount} ${this._inputAccInfo.ariaDescribedBy}`.trim() : `${this.suggestionsTextId} ${this.valueStateTextId} ${this.suggestionsCount}`.trim();
10541058

10551059
return {
1056-
"wrapper": {
1057-
},
10581060
"input": {
1059-
"ariaDescribedBy": ariaDescribedBy,
1061+
"ariaDescribedBy": ariaDescribedBy || undefined,
10601062
"ariaInvalid": this.valueState === ValueState.Error ? "true" : undefined,
10611063
"ariaHasPopup": this._inputAccInfo.ariaHasPopup ? this._inputAccInfo.ariaHasPopup : ariaHasPopupDefault,
10621064
"ariaAutoComplete": this._inputAccInfo.ariaAutoComplete ? this._inputAccInfo.ariaAutoComplete : ariaAutoCompleteDefault,

packages/main/test/pages/Input.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ <h3> Input disabled</h3>
7878
<input />
7979

8080
<h3> Input maxLength = 5</h3>
81-
<ui5-input maxLength="5" placeholder="Max length of 5"></ui5-input>
81+
<ui5-input id="input-max-length" maxLength="5" placeholder="Max length of 5"></ui5-input>
8282

8383
<h3> Input valueState Success</h3>
8484
<ui5-input id="input3" value-state="Success" placeholder="Success state ...">

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

+7
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ describe("Input general interaction", () => {
289289
assert.ok(respPopover, "Responsive popover with valueStateMessage should be opened.");
290290
});
291291

292+
it("Checks if aria-describedby is renderd if not neccessary", () => {
293+
const input = browser.$("#input-max-length"); // Input with no show-suggestions attribute
294+
const innerInput = input.shadow$("input");
295+
296+
assert.notOk(innerInput.getAttribute("aria-describedby"), "aria-describedby is not rendered");
297+
});
298+
292299
it("Checks if aria-label is reflected in the shadow DOM", () => {
293300
const input = browser.$("#aria-label-input");
294301
const innerInput = input.shadow$("input");

0 commit comments

Comments
 (0)