pleroma/app/soapbox/components/stop-propagation.tsx
2022-11-19 14:36:58 -06:00

28 lines
No EOL
780 B
TypeScript

import React from 'react';
interface IStopPropagation {
children: React.ReactNode,
}
/**
* Prevent mouse events from bubbling up.
*
* Why is this needed? Because `onClick`, `onMouseDown`, and `onMouseUp` are 3 separate events.
* To prevent a lot of code duplication, this component can stop all mouse events.
* Plus, placing it in the component tree makes it more readable.
*/
const StopPropagation: React.FC<IStopPropagation> = ({ children }) => {
const handler: React.MouseEventHandler<HTMLDivElement> = (e) => {
e.stopPropagation();
};
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div onClick={handler} onMouseDown={handler} onMouseUp={handler}>
{children}
</div>
);
};
export default StopPropagation;