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): tokens are not deletable when multi-input is readonly #9905

Merged
merged 2 commits into from
Sep 24, 2024
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
4 changes: 4 additions & 0 deletions packages/main/src/MultiInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ class MultiInput extends Input implements IFormInputElement {

this.style.setProperty(getScopedVarName("--_ui5-input-icons-count"), `${this.iconsCount}`);
this.tokenizerAvailable = this.tokens && this.tokens.length > 0;

if (this.tokenizer) {
this.tokenizer.readonly = this.readonly;
}
}

onAfterRendering() {
Expand Down
42 changes: 34 additions & 8 deletions packages/main/test/specs/MultiInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,45 @@ describe("MultiInput general interaction", () => {
assert.strictEqual(await mi2.getAttribute("placeholder"), "", "a token is added after selection");
});

it("should NOT fire token-delete when MI is readonly", async () => {
it("Tokens should not have delete icon when MI is readonly", async () => {
const input = await browser.$("#readonly-mi");
const deleteIcon = input.$$("ui5-token")[0].shadow$("ui5-icon");

// Act
await deleteIcon.click();
await browser.keys("Backspace");
await browser.keys("Backspace");
await browser.keys("Delete");
const tokens = await input.$$("ui5-token");
const length = tokens.length;
let numTokensWithDeleteIcon = 0;

for (const token of tokens) {
const icon = await token.shadow$("ui5-icon");
if (await icon.isExisting()){
numTokensWithDeleteIcon++;
}
};

// Assert
assert.strictEqual(length, 4, "The tokenizer has 4 tokens");
assert.strictEqual(numTokensWithDeleteIcon, 0, "Tokens should not have delete icon");
});

it("Tokens should not have delete icon when MI is readonly and displayed in n-more popover", async () => {
const input = await browser.$("#readonly-mi");
const tokenizer = await input.shadow$("ui5-tokenizer");
const nMoreLabel = await tokenizer.shadow$(".ui5-tokenizer-more-text");

await nMoreLabel.click();

const tokens = await tokenizer.shadow$("ui5-responsive-popover").$$("ui5-li");
let numTokensWithDeleteIcon = 0;

for (const listItem of tokens) {
const closeBtn = await listItem.shadow$("ui5-button");
if (await closeBtn.isExisting()){
numTokensWithDeleteIcon++;
}
};

// Assert
assert.strictEqual(tokens.length, 4, "The tokenizer has 4 tokens");
assert.strictEqual(tokens.length, 4, "The tokenizer popover has 4 tokens");
assert.strictEqual(numTokensWithDeleteIcon, 0, "Tokens in list should not have delete icon");
});

it("should empty the field when value is cleared in the change handler", async () => {
Expand Down