Skip to content

Commit

Permalink
fix: revert useClickOutside behaviour in dialog & menu (#1394)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Jul 17, 2024
1 parent 9476ae9 commit 686bd1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/core/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,21 @@ const DialogCard = forwardRef(function DialogCard(
)

useClickOutside(
(event: MouseEvent) => {
if (!isTopLayer || !onClickOutside) return
useCallback(
(event) => {
if (!isTopLayer || !onClickOutside) return

const target = event.target as Node | null
const target = event.target as Node | null

if (target && !isTargetWithinScope(boundaryElement, portalElement, target)) {
// Ignore clicks outside of the scope
return
}
if (target && !isTargetWithinScope(boundaryElement, portalElement, target)) {
// Ignore clicks outside of the scope
return
}

onClickOutside()
},
onClickOutside()
},
[boundaryElement, isTopLayer, onClickOutside, portalElement],
),
[rootElement],
)

Expand Down
8 changes: 7 additions & 1 deletion src/core/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ export const Menu = forwardRef(function Menu(
}, [activeIndex, onItemSelect])

// Close menu when clicking outside
useClickOutside((event) => isTopLayer && onClickOutside && onClickOutside(event), [rootElement])
useClickOutside(
useCallback(
(event) => isTopLayer && onClickOutside && onClickOutside(event),
[isTopLayer, onClickOutside],
),
[rootElement],
)

// Close menu when pressing Escape
useGlobalKeyDown(
Expand Down

0 comments on commit 686bd1f

Please sign in to comment.