From 017185e0a5fabb62ff87d4078a11f8a3b647069f Mon Sep 17 00:00:00 2001 From: aleksandar-terziev Date: Thu, 28 Aug 2025 09:30:51 +0300 Subject: [PATCH] fix(ui5-input): emit change when suggestion is clicked --- packages/main/cypress/specs/Input.cy.tsx | 72 ++++++++++++++++++++++++ packages/main/src/Input.ts | 3 +- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/packages/main/cypress/specs/Input.cy.tsx b/packages/main/cypress/specs/Input.cy.tsx index 251af70efccd..66051b43c17d 100644 --- a/packages/main/cypress/specs/Input.cy.tsx +++ b/packages/main/cypress/specs/Input.cy.tsx @@ -443,6 +443,78 @@ describe("Input general interaction", () => { cy.get("@input") .should("have.prop", "typedInValue", ""); }); + + it("Should fire 'change' event once when clicking a suggestion equal to the typed value", () => { + const onChange = cy.spy().as("onChange"); + const onSelectionChange = cy.spy().as("onSelectionChange"); + + cy.mount( + + + + + ); + + cy.get("#input-equal-click") + .shadow() + .find("input") + .click() + .realType("Cozy"); + + cy.get("#input-equal-click") + .shadow() + .find("[ui5-responsive-popover]") + .ui5ResponsivePopoverOpened(); + + cy.get('#input-equal-click') + .find('ui5-suggestion-item[text="Cozy"]') + .click(); + + cy.get("#input-equal-click").should("have.value", "Cozy"); + cy.get("@onChange").should("have.been.calledOnce"); + }); + + it("Should fire 'change' event once when selecting a suggestion equal to the typed value with keyboard", () => { + const onChange = cy.spy().as("onChange"); + const onSelectionChange = cy.spy().as("onSelectionChange"); + + cy.mount( + + + + + ); + + cy.get("#input-equal-keyboard") + .shadow() + .find("input") + .click() + .realType("Cozy"); + + cy.get("#input-equal-keyboard") + .shadow() + .find("[ui5-responsive-popover]") + .ui5ResponsivePopoverOpened(); + + cy.realPress("ArrowDown"); + cy.realPress("Enter"); + + cy.get("#input-equal-keyboard").should("have.value", "Cozy"); + cy.get("@onChange").should("have.been.calledOnce"); + cy.get("@onSelectionChange").should("have.been.calledOnce"); + }); }); describe("Input arrow navigation", () => { diff --git a/packages/main/src/Input.ts b/packages/main/src/Input.ts index 2e7283b07b6c..5dc3cd619659 100644 --- a/packages/main/src/Input.ts +++ b/packages/main/src/Input.ts @@ -1424,10 +1424,9 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement return; } - const value = this.typedInValue || this.value; const itemText = item.text || ""; const fireChange = keyboardUsed - ? this.valueBeforeItemSelection !== itemText : value !== itemText; + ? this.valueBeforeItemSelection !== itemText : this.previousValue !== itemText; this.hasSuggestionItemSelected = true; this.value = itemText;