Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes incorrect mouseup event handling in overlay #1665

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/overlay/src/Overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const Overlay = memo(function Overlay({
const [previousActiveElement, setPreviousActiveElement] = useState(null)
const [status, setStatus] = useState(isShown ? 'entering' : 'exited')
const containerRef = useRef(null)
const mouseDownTargetRef = useRef(null)

useEffect(() => {
if (isShown) {
Expand Down Expand Up @@ -238,12 +239,22 @@ const Overlay = memo(function Overlay({
safeInvoke(onExited, node)
}

const handleMouseDown = event => {
mouseDownTargetRef.current = event.target
}

const handleMouseUp = (event) => {
if (mouseDownTargetRef.current === event.target) {
close()
}
}

const handleBackdropClick = event => {
if (event.target !== event.currentTarget || !shouldCloseOnClick) {
return
}

close()
handleMouseUp(event)
}

if (status === 'exited') {
Expand All @@ -270,6 +281,7 @@ const Overlay = memo(function Overlay({
{state => (
<Box
onClick={handleBackdropClick}
onMouseDown={handleMouseDown}
ref={containerRef}
position="fixed"
top={0}
Expand Down