Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-multi-input): fix multiple token addition #8144

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion packages/main/src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ class Tokenizer extends UI5Element {
}

onBeforeRendering() {
this._nMoreCount = this.overflownTokens.length;
this._tokensCount = this._getTokens().length;

this._tokens.forEach(token => {
Expand Down Expand Up @@ -271,6 +270,8 @@ class Tokenizer extends UI5Element {
}

async onAfterRendering() {
this._nMoreCount = this.overflownTokens.length;

if (!this._getTokens().length) {
const popover = await this.getPopover();
popover.close();
Expand Down
15 changes: 15 additions & 0 deletions packages/main/test/pages/MultiInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ <h1 class="sample-container-title">Multi Input without tokens</h1>
<br>
<br>

<h1 class="sample-container-title">Add multiple tokens</h1>
<ui5-multi-input id="no-tokens2"></ui5-multi-input>
<br>
<br>

<ui5-button id="add-multiple-tokens">Add more tokens</ui5-button>

<br>
<br>

<h1 class="sample-container-title">Multi Input with 1 token</h1>
<ui5-multi-input id="single-token">
<ui5-token slot="tokens" text="Amet"></ui5-token>
Expand Down Expand Up @@ -380,6 +390,11 @@ <h1 class="sample-container-title">Eventing</h1>
addTokenToMI(createTokenFromText("test"), "no-tokens");
});

document.getElementById("add-multiple-tokens").addEventListener("click", function(event) {
addTokenToMI(createTokenFromText("One"), "no-tokens2");
addTokenToMI(createTokenFromText("Two"), "no-tokens2");
});

document.getElementById("add-to-single").addEventListener("click", function(event) {
addTokenToMI(createTokenFromText("test"), "single-token");
});
Expand Down
14 changes: 14 additions & 0 deletions packages/main/test/specs/MultiInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ describe("MultiInput general interaction", () => {
assert.notOk(await allTokens[1].getProperty("overflows"), "Token should not overflow");
});

it ("adds multiple tokens to multi input", async () => {
const mi = await browser.$("#no-tokens2");
const btn = await browser.$("#add-multiple-tokens");

await btn.click();

assert.strictEqual((await mi.$$("ui5-token")).length, 2, "should have 2 tokens");

let allTokens = await mi.$$("ui5-token");

assert.notOk(await allTokens[0].getProperty("overflows"), "Token 1 should not overflow");
assert.notOk(await allTokens[1].getProperty("overflows"), "Token 2 should not overflow");
});

it ("adds an overflowing token to multi input", async () => {
const mi = await browser.$("#multiple-token");
const btn = await browser.$("#add-to-multiple");
Expand Down