user-event icon indicating copy to clipboard operation
user-event copied to clipboard

Typing Backspace multiple times results in wrong cursor position

Open JesseCheng77 opened this issue 3 years ago • 1 comments

Reproduction example

https://codesandbox.io/s/elastic-surf-6qegdh?file=/src/App.test.js

Prerequisites

  1. Render <input type="text" />
  2. Type abc
  3. Press {ArrowLeft}{Backspace}{Backspace}

Expected behavior

input element value should be 'c' and cursor position should be 0

Actual behavior

The input element value is "a" and the cursor position is 1

User-event version

14.4.3

Environment

Testing Library framework:

JS framework:

Test environment:

DOM implementation:

Additional context

No response

JesseCheng77 avatar Sep 16 '22 10:09 JesseCheng77

I experience similar problem and it boiled down to incorrect behavior with React 17 starting v14.2.6.

Test:

  1. Render <input type="text" /> and focus it.
  2. Using only keyboard press a, b, e, h
  3. Press {ArrowLeft}, {ArrowLeft}
  4. Press C, D
  5. Press {ArrowRight}
  6. Press F, G

Expected input value: abCDeFGh Received input value: abCehDFG

Codepens:

Most likely this PR caused regression for React 17 in v14.2.6.

hudochenkov avatar Oct 21 '22 10:10 hudochenkov