ai-stories-factory / src /lib /utils /putTextInTextAreaElement.ts
jbilcke-hf's picture
jbilcke-hf HF staff
add button for more randomness
c8c2f6c
raw
history blame
473 Bytes
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)
}