/** Emit `onInput` event on give input with given value */
export function changeInputValue(input: HTMLInputElement, value: string) {
  // React >= 15.6 don't allow setting input.value manually, because they overwrite `value.set` of
  // standard input. That's why we should use this hack to get original `value.set` method.
  // See https://stackoverflow.com/a/46012210/1778685
  const nativeInputValueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;
  nativeInputValueSetter?.call(input, value);

  // We should emit `input.onInput` event for given textfield when user hide the input
  const event = new Event('input', { bubbles: true });
  input.dispatchEvent(event);
}
