Skip to content

fix(ui5-combobox): properly navigate with arrow up/down keys #11418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
71 changes: 71 additions & 0 deletions packages/main/cypress/specs/ComboBox.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,77 @@ describe("Keyboard interaction", () => {
cy.get("@combobox")
.find("[ui5-cb-item]").eq(2).should("have.prop", "selected", true);
});
it("tests navigating with arrow down and up when item text is the same as in the previous selected item", () => {
cy.mount(
<ComboBox>
<ComboBoxItem text="Bulgaria"></ComboBoxItem>
<ComboBoxItem text="Bulgaria"></ComboBoxItem>
<ComboBoxItem text="Bulgaria"></ComboBoxItem>
</ComboBox>
);

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

cy.get<ComboBox>("@combobox")
.shadow()
.find("input")
.as("inner");

cy.get("@inner").focus();

cy.get("@inner").realPress("F4");
cy.get("@combobox")
.find("[ui5-cb-item]").eq(0).should("have.prop", "selected", true);

cy.get("@inner").realPress("ArrowDown");
cy.get("@combobox")
.find("[ui5-cb-item]").eq(1).should("have.prop", "selected", true);

cy.get("@inner").realPress("ArrowDown");
cy.get("@combobox")
.find("[ui5-cb-item]").eq(2).should("have.prop", "selected", true);

cy.get("@inner").realPress("ArrowUp");
cy.get("@combobox")
.find("[ui5-cb-item]").eq(1).should("have.prop", "selected", true);
});

it("tests navigating with arrow down and up when item text is the same as in the previous selected item (with grouping)", () => {
cy.mount(
<ComboBox>
<ComboBoxItemGroup header-text="Bulgaria">
<ComboBoxItem text="Bulgaria"></ComboBoxItem>
<ComboBoxItem text="Bulgaria"></ComboBoxItem>
<ComboBoxItem text="Bulgaria"></ComboBoxItem>
</ComboBoxItemGroup>
</ComboBox>
);

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

cy.get<ComboBox>("@combobox")
.shadow()
.find("input")
.as("inner");

cy.get("@inner").focus();

cy.get("@inner").realPress("F4");
cy.get("@combobox")
.find("[ui5-cb-item]").eq(0).should("have.prop", "selected", true);

cy.get("@inner").realPress("ArrowDown");
cy.get("@combobox")
.find("[ui5-cb-item]").eq(1).should("have.prop", "selected", true);

cy.get("@inner").realPress("ArrowDown");
cy.get("@combobox")
.find("[ui5-cb-item]").eq(2).should("have.prop", "selected", true);

cy.get("@inner").realPress("ArrowUp");
cy.get("@combobox")
.find("[ui5-cb-item]").eq(1).should("have.prop", "selected", true);
});
});

describe("Event firing", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/ComboBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ class ComboBox extends UI5Element implements IFormInputElement {
const matchingItems: Array<IComboBoxItem> = this._startsWithMatchingItems(current);

if (matchingItems.length) {
const exactMatch = matchingItems.find(item => item.text === current);
const exactMatch = matchingItems.find(item => item.text === current && item.focused);
return exactMatch ?? matchingItems[0];
}
}
Expand All @@ -1101,7 +1101,7 @@ class ComboBox extends UI5Element implements IFormInputElement {

this._filteredItems.forEach(item => {
if (!shouldSelectionBeCleared && !itemToBeSelected) {
itemToBeSelected = ((!item.isGroupItem && (item.text === this.value)) ? item : item?.items?.find(i => i.text === this.value));
itemToBeSelected = ((!item.isGroupItem && (item.text === this.value && item === currentlyFocusedItem)) ? item : item?.items?.find(i => i.text === this.value && i.focused));
}
});

Expand Down
Loading