@razorpay/blade
Version:
The Design System that powers Razorpay
31 lines (28 loc) • 1.01 kB
JavaScript
/**
* Fires native events on a given HTML element reference.
*
* @param ref - A React ref object pointing to an HTML element or null.
* @param eventTypes - An array of event types to be dispatched. Supported event types are 'change' and 'input'.
*
* @remarks
* This function creates and dispatches native events of the specified types on the element referenced by `ref`.
* If `ref` is null, a warning is logged to the console.
*
* @example
* ```typescript
* const inputRef = React.createRef<HTMLInputElement>();
* fireNativeEvent(inputRef, ['change', 'input']);
* ```
*/
var fireNativeEvent = function fireNativeEvent(ref, eventTypes) {
if (!ref) return;
eventTypes.forEach(function (eventType) {
var _ref$current;
var event = new Event(eventType, {
bubbles: true
});
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.dispatchEvent(event);
});
};
export { fireNativeEvent };
//# sourceMappingURL=fireNativeEvent.web.js.map