Skip to content

Commit 941a414

Browse files
authored
fix(ui5-combobox): announce selected item (#3358)
* fix(ui5-combobox): announce selected item * apply comments
1 parent a9edc74 commit 941a414

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages/main/src/ComboBox.js

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
44
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js";
55
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
66
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
7+
import announce from "@ui5/webcomponents-base/dist/util/InvisibleMessage.js";
78
import "@ui5/webcomponents-icons/dist/slim-arrow-down.js";
89
import "@ui5/webcomponents-icons/dist/decline.js";
910
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
@@ -24,6 +25,8 @@ import {
2425
VALUE_STATE_INFORMATION,
2526
INPUT_SUGGESTIONS_TITLE,
2627
SELECT_OPTIONS,
28+
LIST_ITEM_POSITION,
29+
LIST_ITEM_SELECTED,
2730
} from "./generated/i18n/i18n-defaults.js";
2831

2932
// Templates
@@ -589,6 +592,10 @@ class ComboBox extends UI5Element {
589592
indexOfItem += isArrowDown ? 1 : -1;
590593
indexOfItem = indexOfItem < 0 ? 0 : indexOfItem;
591594

595+
if (this.responsivePopover.opened) {
596+
this.announceSelectedItem(indexOfItem);
597+
}
598+
592599
this._filteredItems[indexOfItem].focused = true;
593600
this.filterValue = this._filteredItems[indexOfItem].text;
594601
this._isKeyNavigation = true;
@@ -721,6 +728,13 @@ class ComboBox extends UI5Element {
721728
this._itemFocused = true;
722729
}
723730

731+
announceSelectedItem(indexOfItem) {
732+
const itemPositionText = this.i18nBundle.getText(LIST_ITEM_POSITION, [indexOfItem + 1], [this._filteredItems.length]);
733+
const itemSelectionText = this.i18nBundle.getText(LIST_ITEM_SELECTED);
734+
735+
announce(`${itemPositionText} ${itemSelectionText}`, "Polite");
736+
}
737+
724738
get _headerTitleText() {
725739
return this.i18nBundle.getText(INPUT_SUGGESTIONS_TITLE);
726740
}

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

+24
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,27 @@ describe("General interaction", () => {
328328
assert.strictEqual(listItem.shadow$(".ui5-li-additional-text").getText(), "DZ", "Additional item text should be displayed");
329329
});
330330
});
331+
332+
describe("Accessibility", () => {
333+
334+
it ("Announce item on selection", () => {
335+
const combo = $("#combo");
336+
const arrow = combo.shadow$("[input-icon]");
337+
const input = combo.shadow$("#ui5-combobox-input");
338+
const invisibleMessageSpan = $(".ui5-invisiblemessage-polite");
339+
const itemAnnouncement1 = "List item 1 of 11 Selected";
340+
const itemAnnouncement2 = "List item 2 of 11 Selected";
341+
342+
arrow.click();
343+
344+
assert.strictEqual(invisibleMessageSpan.getHTML(false), "", "Span value should be empty.")
345+
346+
input.keys("ArrowDown");
347+
348+
assert.strictEqual(invisibleMessageSpan.getHTML(false), itemAnnouncement1, "Span value is correct.")
349+
350+
input.keys("ArrowDown");
351+
352+
assert.strictEqual(invisibleMessageSpan.getHTML(false), itemAnnouncement2, "Span value is correct.")
353+
});
354+
});

0 commit comments

Comments
 (0)