Skip to content

Commit c892bbb

Browse files
fix(ui5-multi-input): show suggestions instead of tokens on desktop
1 parent dee55cf commit c892bbb

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,43 @@ describe("MultiInput tokens", () => {
371371
cy.get("@changeSpy").should("have.been.calledOnce");
372372
});
373373

374+
it("should show suggestions (not tokens) when typing for a second token", () => {
375+
cy.mount(
376+
<MultiInput showSuggestions>
377+
<Token slot="tokens" text="Argentina"></Token>
378+
<SuggestionItem text="Bulgaria"></SuggestionItem>
379+
<SuggestionItem text="Brazil"></SuggestionItem>
380+
<SuggestionItem text="Belgium"></SuggestionItem>
381+
</MultiInput>
382+
);
383+
384+
cy.get("[ui5-multi-input]")
385+
.shadow()
386+
.find("input")
387+
.as("input");
388+
389+
cy.get("@input")
390+
.realClick();
391+
392+
cy.get("@input")
393+
.realType("b");
394+
395+
cy.get("[ui5-multi-input]")
396+
.shadow()
397+
.find<ResponsivePopover>("[ui5-responsive-popover]")
398+
.as("popover")
399+
.ui5ResponsivePopoverOpened();
400+
401+
cy.get("[ui5-multi-input]")
402+
.find("[ui5-suggestion-item]")
403+
.should("have.length", 3)
404+
.should("be.visible");
405+
406+
cy.get("@popover")
407+
.find("[ui5-list].ui5-tokenizer-list")
408+
.should("not.exist");
409+
});
410+
374411
it("Tokens should not have delete icon when MI is readonly", () => {
375412
cy.mount(
376413
<MultiInput id="readonly-mi" readonly>

packages/main/src/MultiInput.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
isEnter,
1717

1818
} from "@ui5/webcomponents-base/dist/Keys.js";
19+
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js";
1920
import type { ITabbable } from "@ui5/webcomponents-base/dist/delegate/ItemNavigation.js";
2021
import { getScopedVarName } from "@ui5/webcomponents-base/dist/CustomElementsScope.js";
2122
import type { IFormInputElement } from "@ui5/webcomponents-base/dist/features/InputElementsFormSupport.js";
@@ -235,8 +236,6 @@ class MultiInput extends Input implements IFormInputElement {
235236
}
236237

237238
innerFocusIn() {
238-
this.tokenizer._scrollToEndOnExpand = true;
239-
this.tokenizer.expanded = true;
240239
this.focused = true;
241240

242241
this.tokens.forEach(token => {
@@ -369,20 +368,23 @@ class MultiInput extends Input implements IFormInputElement {
369368
if (this.tokenizer) {
370369
this.tokenizer.readonly = this.readonly;
371370
}
372-
373-
// Reset toggle state if there are tokens and dialog is about to open
374-
if (this.tokens.length > 0 && !this._userToggledShowTokens) {
375-
this._showTokensInSuggestions = true;
376-
}
377371
}
378372

379373
/**
380-
* Override the _handlePickerAfterOpen method to reset toggle state when dialog opens with tokens
374+
* Override the _handlePickerAfterOpen method to handle token display based on device type
381375
*/
382376
_handlePickerAfterOpen() {
383377
if (this.tokens.length > 0) {
384-
this._showTokensInSuggestions = true;
378+
// On mobile: show tokens by default (for filter dialog feature)
379+
// On desktop: keep showing suggestions (default behavior)
380+
if (isPhone()) {
381+
this._showTokensInSuggestions = true;
382+
}
385383
this._userToggledShowTokens = false;
384+
385+
// Expand tokenizer to show all tokens and prevent cut-off
386+
this.tokenizer._scrollToEndOnExpand = true;
387+
this.tokenizer.expanded = true;
386388
}
387389

388390
super._handlePickerAfterOpen();
@@ -469,20 +471,15 @@ class MultiInput extends Input implements IFormInputElement {
469471

470472
/**
471473
* Computes the effective state for showing tokens in suggestions.
472-
* Defaults to true when tokens exist, but respects explicit user toggle.
474+
* Returns false (show suggestions) by default, true only when explicitly set.
473475
*/
474476
get _effectiveShowTokensInSuggestions() {
475-
// If no tokens exist, always false
477+
// If no tokens exist, always show suggestions
476478
if (this.tokens.length === 0) {
477479
return false;
478480
}
479481

480-
// If user has never interacted with the toggle, default to true when tokens exist
481-
if (!this._userToggledShowTokens) {
482-
return true;
483-
}
484-
485-
// If user has interacted, respect their choice
482+
// Return the current state (will be true on mobile after picker opens, false otherwise)
486483
return this._showTokensInSuggestions;
487484
}
488485
}

0 commit comments

Comments
 (0)