Skip to content

Commit

Permalink
fix(ui5-combobox): update picker items while open
Browse files Browse the repository at this point in the history
FIXES: #7011
  • Loading branch information
MapTo0 committed Nov 21, 2023
1 parent 87535f1 commit 123c155
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/main/src/ComboBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ class ComboBox extends UI5Element {
this._filteredItems = this.items;
}

if (this.open && !this._isKeyNavigation) {
this._filteredItems = this._filterItems(this.filterValue);
}

if (!this._initialRendering && document.activeElement === this && !this._filteredItems.length) {
popover?.close();
}
Expand Down Expand Up @@ -535,6 +539,7 @@ class ComboBox extends UI5Element {
_afterClosePopover() {
this._iconPressed = false;
this._filteredItems = this.items;
this.filterValue = "";

// close device's keyboard and prevent further typing
if (isPhone()) {
Expand Down
21 changes: 21 additions & 0 deletions packages/main/test/pages/ComboBox.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,27 @@ <h3>ComboBox in Compact</h3>
</ui5-combobox>
</div>

<div class="demo-section">
<ui5-combobox id="dynamic-items">
<ui5-cb-item text="Hello World"></ui5-cb-item>
</ui5-combobox>

<ui5-button id="add-items-btn">Start adding items</ui5-button>

<script>
const addItemsBtn = document.getElementById("add-items-btn");
const dynamicItemsCb = document.getElementById("dynamic-items");

addItemsBtn.addEventListener("click", () => {
setInterval(() => {
const item = document.createElement("ui5-cb-item");
item.text = "test";
dynamicItemsCb.appendChild(item);
}, 1000);
});
</script>
</div>

<script type="module">
document.getElementById("lazy").addEventListener("ui5-input", async event => {
const { value } = event.target;
Expand Down
20 changes: 20 additions & 0 deletions packages/main/test/specs/ComboBox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,26 @@ describe("General interaction", () => {
await cb.click();
assert.notOk(await popover.isDisplayedInViewport(), "Popover with valueStateMessage should not be opened.");
});

it ("Should add items dynamically items to the picker", async () => {
await browser.url(`test/pages/ComboBox.html`);

const cb = await $("#dynamic-items");
const btn = await $("#add-items-btn");
const arrow = await cb.shadow$("[input-icon]");

await btn.click();
await arrow.click();

const staticAreaItemClassName = await browser.getStaticAreaItemClassName("#dynamic-items");
const initialListItems = await browser.$(`.${staticAreaItemClassName}`).shadow$("ui5-responsive-popover").$$("ui5-li");

await browser.pause(2000);

const updatedListItems = await browser.$(`.${staticAreaItemClassName}`).shadow$("ui5-responsive-popover").$$("ui5-li");

assert.notEqual(initialListItems.length, updatedListItems.length, "item count should be updated");
});
});

describe("Grouping", () => {
Expand Down

0 comments on commit 123c155

Please sign in to comment.