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' (#8866)

* fix(ui5-multi-input): focus tokens on BACKSPACE for inputs of type 'Number' and 'Email'

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

if (cursorPosition === 0 && lastToken) {
// selectionStart property applies only to inputs of types text, search, URL, tel, and password
if (((cursorPosition === null && !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 7b5645d

Please sign in to comment.