@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
15 lines (14 loc) • 758 B
JavaScript
export function dispatchInputEvent(input, value) {
// Changing value prop programmatically doesn't fire a synthetic event or trigger a native
// onChange event. We can not just update .value= in setState because React library overrides
// input value setter but we can call the function directly on the input as context. This will
// cause onChange events to fire no matter how value is updated.
if (input) {
const nativeInputValue = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), 'value');
if (nativeInputValue && nativeInputValue.set) {
nativeInputValue.set.call(input, value);
}
const event = new Event('input', { bubbles: true });
input.dispatchEvent(event);
}
}