Skip to content

Commit

Permalink
Fix typeIn not working in React
Browse files Browse the repository at this point in the history
  • Loading branch information
artemave committed Jun 17, 2019
1 parent 95000a7 commit 77a3829
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/sendkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,31 @@ function sendkey (el, char) {
dispatchEvent(el, 'keyup', char)
}

function setElementValue (el, value) {
if (typeof el.get === 'function') { // skip in VDOM
var element = el.get(0)
var nativeInputValueSetter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), 'value').set
if (nativeInputValueSetter) {
nativeInputValueSetter.call(element, value)
} else {
element.value = value
}
} else {
el.val(value)
}
}

function sendkeys (el, text) {
var originalValue = el.val()

if (text.length === 0) {
el.val('')
setElementValue(el, '')
sendkey(el, '')
} else {
for (var n = 0; n < text.length; ++n) {
var char = text[n]
var value = text.substring(0, n + 1)
el.val(value)
setElementValue(el, value)
sendkey(el, char)
}
}
Expand Down

0 comments on commit 77a3829

Please sign in to comment.