From 5c9257bf73b44457a2e9356da767b9fd46801525 Mon Sep 17 00:00:00 2001 From: Dade Cook Date: Sun, 21 Jun 2020 08:48:25 -0400 Subject: [PATCH] fix(type): fix setSelectionRange (#373) Closes #369 Closes #346 --- src/type.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/type.js b/src/type.js index fbf26f98..8e428ff2 100644 --- a/src/type.js +++ b/src/type.js @@ -61,12 +61,19 @@ async function typeImpl( // The reason we have to do this at all is because it actually *is* // programmatically changed by fireEvent.input, so we have to simulate the // browser's default behavior - if (currentValue() === newValue) { + const value = currentValue() + + if (value === newValue) { setSelectionRangeIfNecessary( currentElement(), newSelectionStart, newSelectionStart, ) + } else { + // If the currentValue is different than the expected newValue and we *can* + // change the selection range, than we should set it to the length of the + // currentValue to ensure that the browser behavior is mimicked. + setSelectionRangeIfNecessary(currentElement(), value.length, value.length) } }