Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions packages/main/cypress/specs/Input.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Link from "../../src/Link.js";

import add from "@ui5/webcomponents-icons/dist/add.js";
import type ResponsivePopover from "../../src/ResponsivePopover.js";
import { INPUT_SUGGESTIONS_EXPANDED, INPUT_SUGGESTIONS_COLLAPSED, INPUT_SUGGESTIONS_MORE_HITS } from "../../src/generated/i18n/i18n-defaults.js";

describe("Input Tests", () => {
it("test input event prevention", () => {
Expand Down Expand Up @@ -1364,6 +1365,71 @@ describe("Accessibility", () => {
});
});

describe("Suggestions expanded/collapsed announcement", () => {
it("Should include 'Expanded' in suggestions count when popover opens", () => {
cy.mount(
<Input showSuggestions>
<SuggestionItem text="Item 1" />
<SuggestionItem text="Item 2" />
</Input>
);

cy.get("[ui5-input]")
.as("input")
.realClick();

cy.get("@input")
.shadow()
.find("input")
.realType("I");

cy.get("@input")
.shadow()
.find<ResponsivePopover>("[ui5-responsive-popover]")
.ui5ResponsivePopoverOpened();

cy.get("@input")
.shadow()
.find("#suggestionsCount")
.should("contain.text", INPUT_SUGGESTIONS_EXPANDED.defaultText);
});

it("Should announce 'Collapsed' when suggestions popover closes", () => {
cy.mount(
<Input showSuggestions>
<SuggestionItem text="Item 1" />
<SuggestionItem text="Item 2" />
</Input>
);

cy.get("[ui5-input]")
.as("input")
.realClick();

cy.get("@input")
.shadow()
.find("input")
.realType("I");

cy.get("@input")
.shadow()
.find<ResponsivePopover>("[ui5-responsive-popover]")
.ui5ResponsivePopoverOpened();

cy.realPress("Escape");

cy.get("@input")
.shadow()
.find<ResponsivePopover>("[ui5-responsive-popover]")
.ui5ResponsivePopoverClosed();

cy.get("@input")
.shadow()
.find("#suggestionsCount")
.should("have.text", INPUT_SUGGESTIONS_COLLAPSED.defaultText);
});
});

describe("Attribute propagation", () => {
it("Should change the placeholder of the inner input", () => {
const placeholder = "New placeholder text";
Expand Down
11 changes: 7 additions & 4 deletions packages/main/src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ import {
INPUT_AVALIABLE_VALUES,
INPUT_SUGGESTIONS_OK_BUTTON,
INPUT_SUGGESTIONS_CANCEL_BUTTON,
INPUT_SUGGESTIONS_EXPANDED,
INPUT_SUGGESTIONS_COLLAPSED,
} from "./generated/i18n/i18n-defaults.js";

// Styles
Expand Down Expand Up @@ -1987,20 +1989,21 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
get availableSuggestionsCount() {
if (this.showSuggestions && (this.value || this.Suggestions?.isOpened())) {
const nonGroupItems = this._selectableItems;
const expandedText = Input.i18nBundle.getText(INPUT_SUGGESTIONS_EXPANDED);

switch (nonGroupItems.length) {
case 0:
return Input.i18nBundle.getText(INPUT_SUGGESTIONS_NO_HIT);
return `${Input.i18nBundle.getText(INPUT_SUGGESTIONS_NO_HIT)} ${expandedText}`;

case 1:
return Input.i18nBundle.getText(INPUT_SUGGESTIONS_ONE_HIT);
return `${Input.i18nBundle.getText(INPUT_SUGGESTIONS_ONE_HIT)} ${expandedText}`;

default:
return Input.i18nBundle.getText(INPUT_SUGGESTIONS_MORE_HITS, nonGroupItems.length);
return `${Input.i18nBundle.getText(INPUT_SUGGESTIONS_MORE_HITS, nonGroupItems.length)} ${expandedText}`;
}
}

return undefined;
return this.showSuggestions ? Input.i18nBundle.getText(INPUT_SUGGESTIONS_COLLAPSED) : undefined;
}

get step() {
Expand Down
6 changes: 6 additions & 0 deletions packages/main/src/i18n/messagebundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ INPUT_SUGGESTIONS_MORE_HITS={0} results are available
#XACT: ARIA announcement for the Input suggestion result if no hit
INPUT_SUGGESTIONS_NO_HIT=No results

#XACT: ARIA announcement when suggestions popover is expanded
INPUT_SUGGESTIONS_EXPANDED=Expanded

#XACT: ARIA announcement when suggestions popover is collapsed
INPUT_SUGGESTIONS_COLLAPSED=Collapsed

#XACT: ARIA label for the Input clear icon
INPUT_CLEAR_ICON_ACC_NAME=Clear

Expand Down
Loading