File size: 473 Bytes
c8c2f6c
bcfd882
 
 
c8c2f6c
bcfd882
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export function putTextInTextAreaElement(input?: HTMLTextAreaElement  , text: string = "") {
  if (!input) { return }

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

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

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