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

* fix(ui5-multi-input): prevent double value state message on nMore open

fixes: #8586
  • Loading branch information
ndeshev committed May 9, 2024
1 parent c542aae commit 1461847
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/main/src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
*
* - The particular effect of this property differs depending on the browser
* and the current language settings, especially for type `Number`.
* - Due to browser constraints, certain keyboard interactions may not be available
* for the 'Number' and 'Email' types.
* - The property is mostly intended to be used with touch devices
* that use different soft keyboard layouts depending on the given input type.
* @default "Text"
Expand Down
3 changes: 2 additions & 1 deletion packages/main/src/MultiInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,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 @@ -548,6 +548,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 1461847

Please sign in to comment.