Skip to content

Commit

Permalink
fix: use click outside to trigger also when previous click was on the…
Browse files Browse the repository at this point in the history
… target element.

This fixes and edge case, where the overlay contains a scrollbar and the user scrolls in the
overlay. then clicks outside, the on close is not triggered immediately. with this fix it is
triggerred on first click outside. Before the on close was only triggered on the second
click outside.

Signed-off-by: David Edler <[email protected]>
  • Loading branch information
edlerd committed Nov 11, 2024
1 parent 69413ac commit fc317fd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/useClickOutside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ function useClickOutside(
const handleInitialMouse = useEventCallback((e: MouseEvent) => {
const currentTarget = getRefTarget(ref);

if (currentTarget && contains(currentTarget, e.target as any)) {
if (
currentTarget &&
contains(currentTarget, e.target as any) &&
currentTarget !== e.target
) {
waitingForTrigger.current = true;
}
});
Expand Down

0 comments on commit fc317fd

Please sign in to comment.