StopPropagation: let it be disabled

This commit is contained in:
Alex Gleason 2022-11-19 15:26:07 -06:00
parent 0cea66dcef
commit 6a8d7e4ed3
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 7 additions and 2 deletions

View File

@ -1,7 +1,10 @@
import React from 'react';
interface IStopPropagation {
/** Children to render within the bubble. */
children: React.ReactNode,
/** Whether to prevent mouse events from bubbling. (default: `true`) */
enabled?: boolean,
}
/**
@ -11,10 +14,12 @@ interface IStopPropagation {
* 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 StopPropagation: React.FC<IStopPropagation> = ({ children, enabled = true }) => {
const handler: React.MouseEventHandler<HTMLDivElement> = (e) => {
e.stopPropagation();
if (enabled) {
e.stopPropagation();
}
};
return (