Skip to content

Commit 08a53cb

Browse files
authored
fix(ui5-multiinput): correct backspace behavior in case of value (#13219)
1 parent 48692b5 commit 08a53cb

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

packages/main/cypress/specs/MultiInput.cy.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ describe("Keyboard handling", () => {
12661266
.should("be.focused");
12671267
});
12681268

1269-
it("should focus token last token when caret is at the beginning of the value", () => {
1269+
it("should not focus token on backspace when input has value and caret is at position 0", () => {
12701270
cy.mount(
12711271
<MultiInput id="two-tokens" value="abc">
12721272
<Token slot="tokens" id="firstToken" text="aa"></Token>
@@ -1288,9 +1288,11 @@ describe("Keyboard handling", () => {
12881288

12891289
cy.realPress("Backspace");
12901290

1291-
cy.get("[ui5-token]")
1292-
.eq(1)
1291+
cy.get("@innerInput")
12931292
.should("be.focused");
1293+
1294+
cy.get("@innerInput")
1295+
.should("have.value", "abc");
12941296
});
12951297

12961298
// Test is skipped for now as it fails randomly

packages/main/src/MultiInput.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,11 @@ class MultiInput extends Input implements IFormInputElement {
303303
}
304304

305305
_handleBackspace(e: KeyboardEvent) {
306-
const cursorPosition = this.getDomRef()!.querySelector(`input`)!.selectionStart;
307-
const selectionEnd = this.getDomRef()!.querySelector(`input`)!.selectionEnd;
308-
const isValueSelected = cursorPosition === 0 && selectionEnd === this.value.length;
309306
const tokens = this.tokens;
310307
const lastToken = tokens.length && tokens[tokens.length - 1];
311308

312-
// selectionStart property applies only to inputs of types text, search, URL, tel, and password
313-
if ((!this.value || (this.value && cursorPosition === 0 && !isValueSelected)) && lastToken) {
309+
// Only move focus to the last token if the input is empty
310+
if (!this.value && lastToken) {
314311
e.preventDefault();
315312
lastToken.focus();
316313
this.tokenizer._itemNav.setCurrentItem(lastToken);

0 commit comments

Comments
 (0)