File size: 455 Bytes
421fbba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export function putTextInInput(input?: HTMLInputElement, text: string = "") {
  if (!input) { return }

  const nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(
    window.HTMLInputElement.prototype,
    "value"
  )?.set;

  // fallback
  if (!nativeTextAreaValueSetter) {
    input.value = text
    return
  }

  nativeTextAreaValueSetter.call(input, text)
  const event = new Event('input', { bubbles: true });
  input.dispatchEvent(event)
}