Skip to content

Instantly share code, notes, and snippets.

@simenbrekken-visma
Created October 19, 2022 07:33
Show Gist options
  • Save simenbrekken-visma/f0e59853f82021945a5c947b5e2fa407 to your computer and use it in GitHub Desktop.
Save simenbrekken-visma/f0e59853f82021945a5c947b5e2fa407 to your computer and use it in GitHub Desktop.
/**
* React overwrites the native value setter for HTMLInputElement so have to go deeper.
*
* @see https://github.com/facebook/react/issues/11600#issuecomment-345813130
*/
function setNativeInputValue(input: HTMLInputElement, value: string) {
Object.getOwnPropertyDescriptor(
HTMLInputElement.prototype,
'value'
)?.set?.call(input, value);
input.dispatchEvent(new Event('input', { bubbles: true }));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment