Skip to content

Commit

Permalink
Merge pull request #123 from sharmalab/overlay-prop-fix
Browse files Browse the repository at this point in the history
stop propogate click events when vis config open
  • Loading branch information
birm authored Jun 12, 2024
2 parents 62037fa + 3de3d5a commit ab2c3f0
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useContext } from 'react';
import React, { useState, useContext, useEffect } from 'react';
import Button from 'react-bootstrap/Button';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCompressArrowsAlt, faExpandArrowsAlt } from '@fortawesome/free-solid-svg-icons';
Expand All @@ -12,6 +12,7 @@ import './VisGridItemControl.css';
function VisGridItemControl(props) {
const { config } = useContext(ConfigContext);
const [show, setShow] = useState(false);

let btnFilterRemove;
if (props.filters.length > 0 && props.filters.find((f) => f.id === props.id)) {
btnFilterRemove = (
Expand All @@ -26,6 +27,28 @@ function VisGridItemControl(props) {
</Button>
);
}

const stopPropagation = (e) => {
e.stopPropagation();
};

useEffect(() => {
if (show) {
document.addEventListener('mousedown', stopPropagation, true);
document.addEventListener('mousemove', stopPropagation, true);
document.addEventListener('mouseup', stopPropagation, true);
} else {
document.removeEventListener('mousedown', stopPropagation, true);
document.removeEventListener('mousemove', stopPropagation, true);
document.removeEventListener('mouseup', stopPropagation, true);
}
return () => {
document.removeEventListener('mousedown', stopPropagation, true);
document.removeEventListener('mousemove', stopPropagation, true);
document.removeEventListener('mouseup', stopPropagation, true);
};
}, [show]);

return (
<div>
{(props.hover || show) && (
Expand Down

0 comments on commit ab2c3f0

Please sign in to comment.