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
72 changes: 72 additions & 0 deletions packages/main/cypress/specs/Input.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Input
id="input-equal-click"
showSuggestions
noTypeahead
onChange={onChange}
onSelectionChange={onSelectionChange}
>
<SuggestionItem text="Cozy" />
<SuggestionItem text="Compact" />
</Input>
);

cy.get("#input-equal-click")
.shadow()
.find("input")
.click()
.realType("Cozy");

cy.get("#input-equal-click")
.shadow()
.find<ResponsivePopover>("[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(
<Input
id="input-equal-keyboard"
showSuggestions
noTypeahead
onChange={onChange}
onSelectionChange={onSelectionChange}
>
<SuggestionItem text="Cozy" />
<SuggestionItem text="Compact" />
</Input>
);

cy.get("#input-equal-keyboard")
.shadow()
.find("input")
.click()
.realType("Cozy");

cy.get("#input-equal-keyboard")
.shadow()
.find<ResponsivePopover>("[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", () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/main/src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading