Skip to content
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