Skip to content

Commit fecbc81

Browse files
fix(ui5-combobox): handle scrolling to selected item on popover open (#11938)
1 parent 5e2c0fd commit fecbc81

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

packages/main/cypress/specs/ComboBox.cy.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,64 @@ import ComboBoxItem from "../../src/ComboBoxItem.js";
33
import ComboBoxItemGroup from "../../src/ComboBoxItemGroup.js";
44
import Link from "../../src/Link.js";
55
import Input from "../../src/Input.js";
6+
import Button from "../../src/Button.js";
7+
8+
describe("General Interaction", () => {
9+
it("Scrolls the selected item into view after opening the popover", () => {
10+
cy.mount(
11+
<>
12+
<ComboBox>
13+
<ComboBoxItem text="Bulgaria"></ComboBoxItem>
14+
<ComboBoxItem text="Germany"></ComboBoxItem>
15+
<ComboBoxItem text="Austria"></ComboBoxItem>
16+
<ComboBoxItem text="Australia"></ComboBoxItem>
17+
<ComboBoxItem text="Mexico"></ComboBoxItem>
18+
<ComboBoxItem text="Brazil"></ComboBoxItem>
19+
</ComboBox>
20+
<Button>Dummy Button</Button>
21+
</>
22+
);
23+
cy.viewport(500,200);
24+
25+
cy.get("[ui5-combobox]")
26+
.shadow()
27+
.find("[ui5-icon]")
28+
.as("dropdownIcon");
29+
30+
cy.get("@dropdownIcon")
31+
.realClick();
32+
33+
cy.get("[ui5-combobox]")
34+
.shadow()
35+
.find("[ui5-responsive-popover]")
36+
.shadow()
37+
.find(".ui5-popup-content")
38+
.as("scrollContainer");
39+
40+
cy.get("@scrollContainer")
41+
.scrollTo("bottom");
42+
43+
cy.get("[ui5-cb-item")
44+
.eq(4)
45+
.realClick();
46+
47+
cy.get("@dropdownIcon")
48+
.realClick();
49+
50+
cy.get("@scrollContainer")
51+
.scrollTo("top");
52+
53+
cy.get("[ui5-button]")
54+
.realClick();
55+
56+
cy.get("@dropdownIcon")
57+
.realClick();
58+
59+
cy.get("[ui5-cb-item]")
60+
.eq(4)
61+
.should("be.visible");
62+
})
63+
})
664

765
describe("Security", () => {
866
it("tests setting malicious text to items", () => {

packages/main/src/ComboBox.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,15 @@ class ComboBox extends UI5Element implements IFormInputElement {
578578
this._iconPressed = true;
579579
this.inner.focus();
580580
this.fireDecoratorEvent("open");
581+
582+
const allItems = this._getItems();
583+
const currentItem = allItems.find(item => {
584+
return item.selected || item.focused;
585+
});
586+
587+
if (currentItem) {
588+
this._scrollToItem(allItems.indexOf(currentItem));
589+
}
581590
}
582591

583592
_afterClosePopover() {

0 commit comments

Comments
 (0)