Skip to content
Merged
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
58 changes: 58 additions & 0 deletions packages/main/cypress/specs/ComboBox.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,64 @@ import ComboBoxItem from "../../src/ComboBoxItem.js";
import ComboBoxItemGroup from "../../src/ComboBoxItemGroup.js";
import Link from "../../src/Link.js";
import Input from "../../src/Input.js";
import Button from "../../src/Button.js";

describe("General Interaction", () => {
it("Scrolls the selected item into view after opening the popover", () => {
cy.mount(
<>
<ComboBox>
<ComboBoxItem text="Bulgaria"></ComboBoxItem>
<ComboBoxItem text="Germany"></ComboBoxItem>
<ComboBoxItem text="Austria"></ComboBoxItem>
<ComboBoxItem text="Australia"></ComboBoxItem>
<ComboBoxItem text="Mexico"></ComboBoxItem>
<ComboBoxItem text="Brazil"></ComboBoxItem>
</ComboBox>
<Button>Dummy Button</Button>
</>
);
cy.viewport(500,200);

cy.get("[ui5-combobox]")
.shadow()
.find("[ui5-icon]")
.as("dropdownIcon");

cy.get("@dropdownIcon")
.realClick();

cy.get("[ui5-combobox]")
.shadow()
.find("[ui5-responsive-popover]")
.shadow()
.find(".ui5-popup-content")
.as("scrollContainer");

cy.get("@scrollContainer")
.scrollTo("bottom");

cy.get("[ui5-cb-item")
.eq(4)
.realClick();

cy.get("@dropdownIcon")
.realClick();

cy.get("@scrollContainer")
.scrollTo("top");

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

cy.get("@dropdownIcon")
.realClick();

cy.get("[ui5-cb-item]")
.eq(4)
.should("be.visible");
})
})

describe("Security", () => {
it("tests setting malicious text to items", () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/main/src/ComboBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,15 @@ class ComboBox extends UI5Element implements IFormInputElement {
this._iconPressed = true;
this.inner.focus();
this.fireDecoratorEvent("open");

const allItems = this._getItems();
const currentItem = allItems.find(item => {
return item.selected || item.focused;
});

if (currentItem) {
this._scrollToItem(allItems.indexOf(currentItem));
}
}

_afterClosePopover() {
Expand Down
Loading