Skip to content

Commit

Permalink
fix(ui5-multi-input): focus tokens on BACKSPACE for inputs of type 'N…
Browse files Browse the repository at this point in the history
…umber' and 'Email'

related to #8712
  • Loading branch information
ndeshev committed Apr 26, 2024
1 parent 4be1540 commit 3a0c2e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/main/src/MultiInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ class MultiInput extends Input {
const tokens = this.tokens;
const lastToken = tokens.length && tokens[tokens.length - 1];

if (cursorPosition === 0 && lastToken) {
// Selection is only permitted with text/search, URL, tel and password.
// The likely reason that selection has been disabled for inputs of type number
// is that on some devices, or under some circumstances (e.g., when the input
// has been is presented as a short list), there might not be a caret.
if ((((this.type === "Number" || this.type === "Email") && !this.value) || cursorPosition === 0) && lastToken) {
e.preventDefault();
lastToken.focus();
this.tokenizer._itemNav.setCurrentItem(lastToken);
Expand Down
15 changes: 15 additions & 0 deletions packages/main/test/specs/MultiInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,21 @@ describe("Keyboard handling", () => {
assert.equal(await input.getProperty("focused"), true, "The input is focused");
});

it("should focus token on backspace for inputs of type 'Number' and 'Email'", async () => {
const input = await browser.$("#two-tokens");
const innerInput = await input.shadow$("input");
const lastToken = await browser.$("#two-tokens ui5-token#secondToken");

// Act
await input.setProperty("value", "");
await input.setProperty("type", "Number");

await innerInput.click();
await browser.keys("Backspace");

assert.ok(await lastToken.getProperty("focused"), "The last token is focused on Backspace");
});

it("should delete token on backspace", async () => {
const input = await browser.$("#two-tokens");
const innerInput = await input.shadow$("input");
Expand Down

0 comments on commit 3a0c2e9

Please sign in to comment.