Files
jitsi-meet/react/features/base/react/functions.js
2017-02-02 09:45:34 -06:00

29 lines
1.0 KiB
JavaScript

/* @flow */
/**
* Prevents further propagation of the events to be handler by a specific event
* handler/listener in the capturing and bubbling phases.
*
* @param {Function} eventHandler - The event handler/listener which handles
* events that need to be stopped from propagating.
* @returns {Function} An event handler/listener to be used in place of the
* specified eventHandler in order to stop the events from propagating.
*/
export function stopEventPropagation<T>(eventHandler: (ev: Event) => T)
: (ev: Event) => T {
return (ev: Event) => {
const r = eventHandler(ev);
// React Native does not propagate the press event so, for the sake of
// cross-platform compatibility, stop the propagation on Web as well.
// Additionally, use feature checking in order to deal with browser
// differences.
if (ev && ev.stopPropagation) {
ev.stopPropagation();
ev.preventDefault && ev.preventDefault();
}
return r;
};
}