@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
19 lines (18 loc) • 914 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.dispatchInputEvent = void 0;
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);
}
}
exports.dispatchInputEvent = dispatchInputEvent;
;