Skip to content

Commit c8e0493

Browse files
fix(ui5-input): emit change when suggestion is clicked
1 parent 81c1076 commit c8e0493

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,3 +2529,41 @@ describe("Property open", () => {
25292529
.ui5ResponsivePopoverClosed();
25302530
});
25312531
});
2532+
2533+
describe("Suggestion click", () => {
2534+
it("Fires change once when clicking a suggestion equal to the typed value", () => {
2535+
const onChange = cy.spy().as("onChange");
2536+
const onSelectionChange = cy.spy().as("onSelectionChange");
2537+
2538+
cy.mount(
2539+
<Input
2540+
id="input-equal-click"
2541+
showSuggestions
2542+
noTypeahead
2543+
onChange={onChange}
2544+
onSelectionChange={onSelectionChange}
2545+
>
2546+
<SuggestionItem text="Cozy" />
2547+
<SuggestionItem text="Compact" />
2548+
</Input>
2549+
);
2550+
2551+
cy.get("#input-equal-click")
2552+
.shadow()
2553+
.find("input")
2554+
.click()
2555+
.realType("Cozy");
2556+
2557+
cy.get("#input-equal-click")
2558+
.shadow()
2559+
.find<ResponsivePopover>("[ui5-responsive-popover]")
2560+
.ui5ResponsivePopoverOpened();
2561+
2562+
cy.get('#input-equal-click')
2563+
.find('ui5-suggestion-item[text="Cozy"]')
2564+
.click();
2565+
2566+
cy.get("#input-equal-click").should("have.value", "Cozy");
2567+
cy.get("@onChange").should("have.been.calledOnce");
2568+
});
2569+
});

packages/main/src/Input.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,10 +1424,9 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
14241424
return;
14251425
}
14261426

1427-
const value = this.typedInValue || this.value;
14281427
const itemText = item.text || "";
14291428
const fireChange = keyboardUsed
1430-
? this.valueBeforeItemSelection !== itemText : value !== itemText;
1429+
? this.valueBeforeItemSelection !== itemText : this.previousValue !== itemText;
14311430

14321431
this.hasSuggestionItemSelected = true;
14331432
this.value = itemText;

0 commit comments

Comments
 (0)