Skip to content

Commit 2263b1b

Browse files
committed
fix(type): do not select if not needed
1 parent 9d6ccef commit 2263b1b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/user-event/type.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ async function type(
4040
// The reason we have to do this at all is because it actually *is*
4141
// programmatically changed by await fireEvent.input, so we have to simulate the
4242
// browser's default behavior
43+
const el = currentElement()
44+
const {selectionStart, selectionEnd} = el
4345
if (
44-
currentElement().selectionStart !== null &&
45-
currentValue() === newValue
46+
selectionStart !== null &&
47+
currentValue() === newValue &&
48+
el.setSelectionRange &&
49+
(selectionStart !== newSelectionStart ||
50+
selectionEnd !== newSelectionStart)
4651
) {
47-
currentElement().setSelectionRange?.(newSelectionStart, newSelectionStart)
52+
el.setSelectionRange(newSelectionStart, newSelectionStart)
4853
}
4954
}
5055

0 commit comments

Comments
 (0)