Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(type): fix setSelectionRange (#373)
Closes #369
Closes #346
  • Loading branch information
WretchedDade committed Jun 21, 2020
1 parent 44b9011 commit 5c9257b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/type.js
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 5c9257b

Please sign in to comment.