Skip to content

Commit a7d216c

Browse files
authored
feat(ui5-input): announce suggestions count (#1975)
1 parent aa6fde4 commit a7d216c

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

packages/main/src/Input.hbs

+1
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

+23-1
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
@@ -993,11 +996,13 @@ class Input extends UI5Element {
993996
get accInfo() {
994997
const ariaHasPopupDefault = this.showSuggestions ? "true" : undefined;
995998
const ariaAutoCompleteDefault = this.showSuggestions ? "list" : undefined;
999+
const ariaDescribedBy = this._inputAccInfo.ariaDescribedBy ? `${this.suggestionsTextId} ${this.valueStateTextId} ${this._id}-suggestionsCount ${this._inputAccInfo.ariaDescribedBy}`.trim() : `${this.suggestionsTextId} ${this.valueStateTextId} ${this._id}-suggestionsCount`.trim();
1000+
9961001
return {
9971002
"wrapper": {
9981003
},
9991004
"input": {
1000-
"ariaDescribedBy": this._inputAccInfo.ariaDescribedBy ? `${this.suggestionsTextId} ${this.valueStateTextId} ${this._inputAccInfo.ariaDescribedBy}`.trim() : `${this.suggestionsTextId} ${this.valueStateTextId}`.trim(),
1005+
"ariaDescribedBy": ariaDescribedBy,
10011006
"ariaInvalid": this.valueState === ValueState.Error ? "true" : undefined,
10021007
"ariaHasPopup": this._inputAccInfo.ariaHasPopup ? this._inputAccInfo.ariaHasPopup : ariaHasPopupDefault,
10031008
"ariaAutoComplete": this._inputAccInfo.ariaAutoComplete ? this._inputAccInfo.ariaAutoComplete : ariaAutoCompleteDefault,
@@ -1073,6 +1078,23 @@ class Input extends UI5Element {
10731078
return this.i18nBundle.getText(INPUT_SUGGESTIONS);
10741079
}
10751080

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

packages/main/src/i18n/messagebundle.properties

+9
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)