Skip to content

Commit cb602aa

Browse files
committed
fix(ui5-multi-combobox): remove invalid values on focusout
JIRA: BGSOFUIRILA-4403
1 parent 37e9fef commit cb602aa

2 files changed

Lines changed: 166 additions & 0 deletions

File tree

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

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,161 @@ describe("Validation & Value State", () => {
20002000
.find("[ui5-token]")
20012001
.should("have.length", 1);
20022002
});
2003+
2004+
it("Clears invalid/incomplete values on focus out when noValidation is not set", () => {
2005+
cy.mount(
2006+
<>
2007+
<Button id="btn">Focus target</Button>
2008+
<MultiComboBox>
2009+
<MultiComboBoxItem text="Item 1"></MultiComboBoxItem>
2010+
<MultiComboBoxItem text="Item 2"></MultiComboBoxItem>
2011+
</MultiComboBox>
2012+
</>
2013+
);
2014+
2015+
cy.get("[ui5-multi-combobox]")
2016+
.as("mcb")
2017+
.realClick();
2018+
2019+
cy.get("@mcb")
2020+
.should("be.focused");
2021+
2022+
cy.realType("xyz");
2023+
2024+
cy.get("@mcb")
2025+
.should("have.attr", "value-state", "Negative");
2026+
2027+
cy.get("@mcb")
2028+
.shadow()
2029+
.find("input")
2030+
.should("have.value", "xyz");
2031+
2032+
cy.get("#btn")
2033+
.realClick()
2034+
.should("be.focused");
2035+
2036+
cy.get("@mcb")
2037+
.shadow()
2038+
.find("input")
2039+
.should("have.value", "");
2040+
2041+
cy.get("@mcb")
2042+
.should("have.attr", "value-state", "None");
2043+
});
2044+
2045+
it("Does not clear invalid values on focus out when noValidation is set", () => {
2046+
cy.mount(
2047+
<>
2048+
<Button id="btn">Focus target</Button>
2049+
<MultiComboBox noValidation>
2050+
<MultiComboBoxItem text="Item 1"></MultiComboBoxItem>
2051+
<MultiComboBoxItem text="Item 2"></MultiComboBoxItem>
2052+
</MultiComboBox>
2053+
</>
2054+
);
2055+
2056+
cy.get("[ui5-multi-combobox]")
2057+
.as("mcb")
2058+
.realClick();
2059+
2060+
cy.get("@mcb")
2061+
.should("be.focused");
2062+
2063+
cy.realType("xyz");
2064+
2065+
cy.get("@mcb")
2066+
.shadow()
2067+
.find("input")
2068+
.should("have.value", "xyz");
2069+
2070+
cy.get("#btn")
2071+
.realClick()
2072+
.should("be.focused");
2073+
2074+
cy.get("@mcb")
2075+
.shadow()
2076+
.find("input")
2077+
.should("have.value", "xyz");
2078+
});
2079+
2080+
it("Does not clear valid/matching values on focus out", () => {
2081+
cy.mount(
2082+
<>
2083+
<Button id="btn">Focus target</Button>
2084+
<MultiComboBox>
2085+
<MultiComboBoxItem text="Item 1"></MultiComboBoxItem>
2086+
<MultiComboBoxItem text="Item 2"></MultiComboBoxItem>
2087+
</MultiComboBox>
2088+
</>
2089+
);
2090+
2091+
cy.get("[ui5-multi-combobox]")
2092+
.as("mcb")
2093+
.realClick();
2094+
2095+
cy.get("@mcb")
2096+
.should("be.focused");
2097+
2098+
cy.realType("Item");
2099+
2100+
cy.get("@mcb")
2101+
.shadow()
2102+
.find("input")
2103+
.should("have.value", "Item 1");
2104+
2105+
cy.get("#btn")
2106+
.realClick()
2107+
.should("be.focused");
2108+
2109+
cy.get("@mcb")
2110+
.shadow()
2111+
.find("input")
2112+
.should("have.value", "Item 1");
2113+
});
2114+
2115+
it("Preserves selected tokens when clearing invalid input on focus out", () => {
2116+
cy.mount(
2117+
<>
2118+
<Button id="btn">Focus target</Button>
2119+
<MultiComboBox>
2120+
<MultiComboBoxItem text="Item 1" selected></MultiComboBoxItem>
2121+
<MultiComboBoxItem text="Item 2"></MultiComboBoxItem>
2122+
</MultiComboBox>
2123+
</>
2124+
);
2125+
2126+
cy.get("[ui5-multi-combobox]")
2127+
.as("mcb")
2128+
.shadow()
2129+
.find("[ui5-tokenizer]")
2130+
.find("[ui5-token]")
2131+
.should("have.length", 1);
2132+
2133+
cy.get("@mcb")
2134+
.realClick();
2135+
2136+
cy.realType("xyz");
2137+
2138+
cy.get("@mcb")
2139+
.shadow()
2140+
.find("input")
2141+
.should("have.value", "xyz");
2142+
2143+
cy.get("#btn")
2144+
.realClick()
2145+
.should("be.focused");
2146+
2147+
cy.get("@mcb")
2148+
.shadow()
2149+
.find("input")
2150+
.should("have.value", "");
2151+
2152+
cy.get("@mcb")
2153+
.shadow()
2154+
.find("[ui5-tokenizer]")
2155+
.find("[ui5-token]")
2156+
.should("have.length", 1);
2157+
});
20032158
});
20042159

20052160
describe("Keyboard interaction when pressing Ctrl + Alt + F8 for navigation", () => {

packages/main/src/MultiComboBox.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,17 @@ class MultiComboBox extends UI5Element implements IFormInputElement {
20362036
if ((!this.shadowRoot!.contains(e.relatedTarget as Node) || focusIsGoingInPopover) && !this._deleting && !this._clearingValue) {
20372037
this.focused = false;
20382038

2039+
if (!this.noValidation && this.value) {
2040+
const hasMatchingItem = this._filterItems(this.value).length > 0;
2041+
if (!hasMatchingItem) {
2042+
this.value = "";
2043+
this._lastValue = "";
2044+
if (this.valueState === ValueState.Negative) {
2045+
this._updateValueState(this._effectiveValueState);
2046+
}
2047+
}
2048+
}
2049+
20392050
if (this._lastValue !== this.value) {
20402051
this._inputChange();
20412052
}

0 commit comments

Comments
 (0)