Skip to content

Commit 38a5049

Browse files
authored
fix(ui5-multi-combobox): fix long token deletion (#12514)
* fix(ui5-multi-combobox): fix long token deletion issue fixes: #12423
1 parent fd0d36f commit 38a5049

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,43 @@ describe("General", () => {
332332
.should("have.been.called");
333333
});
334334

335+
it("Should delete token when clicking on token decline icon - regression test for long token deletion fix", () => {
336+
cy.mount(
337+
<MultiComboBox noValidation={true}>
338+
<MultiComboBoxItem selected={true} text="This is an extremely long token text that will definitely trigger the problematic code path in the deletion flow and should be properly deletable"></MultiComboBoxItem>
339+
<MultiComboBoxItem selected={true} text="Item"></MultiComboBoxItem>
340+
</MultiComboBox>
341+
);
342+
343+
cy.get("[ui5-multi-combobox]")
344+
.as("mcb")
345+
.shadow()
346+
.find("[ui5-tokenizer]")
347+
.as("tokenizer")
348+
.invoke('on', 'ui5-token-delete', cy.spy().as('tokenDelete'));
349+
350+
// The first token is the long one and should be hidden in the n-more, so we target the second token
351+
cy.get("@tokenizer")
352+
.find("[ui5-token]")
353+
.eq(1)
354+
.as("token")
355+
.should("exist");
356+
357+
cy.get("@token")
358+
.shadow()
359+
.find("[ui5-icon]")
360+
.realClick();
361+
362+
cy.get("@tokenDelete")
363+
.should("have.been.calledOnce")
364+
.should("have.been.calledWithMatch", Cypress.sinon.match(event => {
365+
return event.detail.tokens.length === 1;
366+
}));
367+
368+
cy.get("@token")
369+
.should("not.exist");
370+
});
371+
335372
it("Autocomplete (typeahead)", () => {
336373
cy.mount(
337374
<MultiComboBox>

packages/main/src/Token.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,6 @@ class Token extends UI5Element implements IToken {
194194
}
195195
}
196196

197-
onBeforeRendering() {
198-
this.toBeDeleted = false;
199-
// this.fireMyEvent("select");
200-
}
201-
202197
get tokenDeletableText() {
203198
return Token.i18nBundle.getText(TOKEN_ARIA_REMOVE);
204199
}

packages/main/src/Tokenizer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,14 @@ class Tokenizer extends UI5Element implements IFormInputElement {
945945
}
946946

947947
_onfocusin(e: FocusEvent) {
948+
const target = e.target as Token;
949+
950+
if (target && target.toBeDeleted) {
951+
this._tokenDeleting = true;
952+
953+
return;
954+
}
955+
948956
this.open = false;
949957
this.expanded = true;
950958
this._addTokenToNavigation(e.target as Token);

packages/main/test/pages/MultiComboBox.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
<br>
6868
<ui5-multi-combobox no-validation id="multi1" accessible-name="MultiComboBox with predefined values">
69+
<ui5-mcb-item selected text="Longest word in the whole universe"></ui5-mcb-item>
6970
<ui5-mcb-item selected text="Cosy"></ui5-mcb-item>
7071
<ui5-mcb-item text="Compact"></ui5-mcb-item>
7172
<ui5-mcb-item selected text="Condensed"></ui5-mcb-item>

0 commit comments

Comments
 (0)