Skip to content

Commit 8dfa088

Browse files
committed
feat(ui5-input): announce suggestions count (#1975)
1 parent 48a89a4 commit 8dfa088

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

packages/main/src/Input.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
{{#if showSuggestions}}
4343
<span id="{{_id}}-suggestionsText" class="ui5-hidden-text">{{suggestionsText}}</span>
4444
<span id="{{_id}}-selectionText" class="ui5-hidden-text" aria-live="polite" role="status"></span>
45+
<span id="{{_id}}-suggestionsCount" class="ui5-hidden-text" aria-live="polite">{{availableSuggestionsCount}}</span>
4546
{{/if}}
4647

4748
{{#if accInfo.input.ariaDescription}}

packages/main/src/Input.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import {
2828
VALUE_STATE_WARNING,
2929
INPUT_SUGGESTIONS,
3030
INPUT_SUGGESTIONS_TITLE,
31+
INPUT_SUGGESTIONS_ONE_HIT,
32+
INPUT_SUGGESTIONS_MORE_HITS,
33+
INPUT_SUGGESTIONS_NO_HIT,
3134
} from "./generated/i18n/i18n-defaults.js";
3235

3336
// Styles
@@ -992,11 +995,13 @@ class Input extends UI5Element {
992995
get accInfo() {
993996
const ariaHasPopupDefault = this.showSuggestions ? "true" : undefined;
994997
const ariaAutoCompleteDefault = this.showSuggestions ? "list" : undefined;
998+
const ariaDescribedBy = this._inputAccInfo.ariaDescribedBy ? `${this.suggestionsTextId} ${this.valueStateTextId} ${this._id}-suggestionsCount ${this._inputAccInfo.ariaDescribedBy}`.trim() : `${this.suggestionsTextId} ${this.valueStateTextId} ${this._id}-suggestionsCount`.trim();
999+
9951000
return {
9961001
"wrapper": {
9971002
},
9981003
"input": {
999-
"ariaDescribedBy": this._inputAccInfo.ariaDescribedBy ? `${this.suggestionsTextId} ${this.valueStateTextId} ${this._inputAccInfo.ariaDescribedBy}`.trim() : `${this.suggestionsTextId} ${this.valueStateTextId}`.trim(),
1004+
"ariaDescribedBy": ariaDescribedBy,
10001005
"ariaInvalid": this.valueState === ValueState.Error ? "true" : undefined,
10011006
"ariaHasPopup": this._inputAccInfo.ariaHasPopup ? this._inputAccInfo.ariaHasPopup : ariaHasPopupDefault,
10021007
"ariaAutoComplete": this._inputAccInfo.ariaAutoComplete ? this._inputAccInfo.ariaAutoComplete : ariaAutoCompleteDefault,
@@ -1072,6 +1077,23 @@ class Input extends UI5Element {
10721077
return this.i18nBundle.getText(INPUT_SUGGESTIONS);
10731078
}
10741079

1080+
get availableSuggestionsCount() {
1081+
if (this.showSuggestions) {
1082+
switch (this.suggestionsTexts.length) {
1083+
case 0:
1084+
return this.i18nBundle.getText(INPUT_SUGGESTIONS_NO_HIT);
1085+
1086+
case 1:
1087+
return this.i18nBundle.getText(INPUT_SUGGESTIONS_ONE_HIT);
1088+
1089+
default:
1090+
return this.i18nBundle.getText(INPUT_SUGGESTIONS_MORE_HITS, this.suggestionsTexts.length);
1091+
}
1092+
}
1093+
1094+
return undefined;
1095+
}
1096+
10751097
get step() {
10761098
return this.type === InputType.Number ? "any" : undefined;
10771099
}

packages/main/src/i18n/messagebundle.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,15 @@ INPUT_SUGGESTIONS=Suggestions available
241241
#XBUT: Default title text for mobile
242242
INPUT_SUGGESTIONS_TITLE=Select
243243

244+
#XACT: ARIA announcement for the Input suggestion result if one hit
245+
INPUT_SUGGESTIONS_ONE_HIT=1 result available
246+
247+
#XACT: ARIA announcement for the Input suggestion result if more than one hit ({0} is the number of hits)
248+
INPUT_SUGGESTIONS_MORE_HITS={0} results are available
249+
250+
#XACT: ARIA announcement for the Input suggestion result if no hit
251+
INPUT_SUGGESTIONS_NO_HIT=No results
252+
244253
#XFLD: Subtle link description label
245254
LINK_SUBTLE=Subtle
246255

0 commit comments

Comments
 (0)