setReactInputValue function infrastructure exported ✓ 100.0%
Last updated: 2026-03-04T23:21:38.390Z
Metrics
LOC: 25
Complexity: 6
Params: 3
Coverage: 100.0% (8/8 lines, 0x executed)
Signature
setReactInputValue(
input: HTMLInputElement | HTMLTextAreaElement,
value: string,
): : void
Summary
Dispatches React-compatible input events. Antd uses React synthetic events — we need to set the value via the native setter and dispatch properly.
Source Code
export function setReactInputValue(
input: HTMLInputElement | HTMLTextAreaElement,
value: string,
): void {
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLInputElement.prototype,
"value",
)?.set;
const nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLTextAreaElement.prototype,
"value",
)?.set;
if (input instanceof HTMLInputElement && nativeInputValueSetter) {
nativeInputValueSetter.call(input, value);
} else if (
input instanceof HTMLTextAreaElement &&
nativeTextAreaValueSetter
) {
nativeTextAreaValueSetter.call(input, value);
}
input.dispatchEvent(new Event("input", { bubbles: true }));
input.dispatchEvent(new Event("change", { bubbles: true }));
}