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
34 changes: 34 additions & 0 deletions packages/main/cypress/specs/ComboBox.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,40 @@ describe("Event firing", () => {
}));
});

it("should NOT fire selection-change event when ComboBox items are set asynchronously after initial render", () => {
cy.mount(
<ComboBox id="async-combo" value="Bulgaria" loading>
{/* Items will be added asynchronously */}
</ComboBox>
);

cy.get("#async-combo")
.invoke('on', 'ui5-selection-change', cy.spy().as('selectionChangeSpy'));

cy.window().then(win => {
const combo = win.document.getElementById("async-combo");
const item1 = win.document.createElement("ui5-cb-item");
item1.setAttribute("text", "Argentina");
const item2 = win.document.createElement("ui5-cb-item");
item2.setAttribute("text", "Bulgaria");
combo?.appendChild(item1);
combo?.appendChild(item2);
(combo as any).loading = false;
});

cy.get("#async-combo").should("not.have.prop", "loading", true);

cy.get("@selectionChangeSpy").should("not.have.been.called");

cy.get("#async-combo").shadow().find("input").realClick();
cy.get("#async-combo").shadow().find("input").clear().realType("Argentina");

cy.get("@selectionChangeSpy").should("have.been.calledOnce");
cy.get("@selectionChangeSpy").should("have.been.calledWithMatch", Cypress.sinon.match(event => {
return event.detail.item.text === "Argentina";
}));
});

it("should check clear icon events", () => {
cy.mount(
<>
Expand Down
6 changes: 6 additions & 0 deletions packages/main/src/ComboBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,12 @@ class ComboBox extends UI5Element implements IFormInputElement {
return item;
});

const noUserInteraction = !this.focused && !this._isKeyNavigation && !this._selectionPerformed && !this._iconPressed;
// Skip firing "selection-change" event if this is initial rendering or if there has been no user interaction yet
if (this._initialRendering || noUserInteraction) {
return;
}

// Fire selection-change event only when selection actually changes
if (previouslySelectedItem !== itemToBeSelected) {
if (itemToBeSelected) {
Expand Down
Loading