Skip to content

Commit

Permalink
fix(): isClickedOutside from the override context should be taken i…
Browse files Browse the repository at this point in the history
…nto consideration on `mouseup` as well because the `mousedown` event propagation might be prevented (more likely than the `mouseup` event)
  • Loading branch information
Yair Even Or authored and Yair Even Or committed Sep 30, 2022
1 parent 8868a1e commit 4e18b0a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/hooks/useClickOutside/useClickOutside.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import OverrideContext from './useClickOutside.context';
* So once a click is detected in the component tree of the target component, we set a flag, which the
* document event handler is checking against. When set to true, the click is considered to be "inside"
* and so it is ignored.
*
*
* This solution is further improved by separating the "click" event into "mousedown" and "mouseup",
* allowing us to cover cases where the mouse is clicked inside the element, but released outside the
* allowing us to cover cases where the mouse is clicked inside the element, but released outside the
* element (for example, when dragging). In such cases the click is still considered as an inside click,
* since it originated inside the element.
*
Expand All @@ -50,7 +50,7 @@ export const useClickOutside = callback => {
}, {current: _document});

useEventListener('mouseup', e => {
isClickedInside.current ? isClickedInside.current = false : callback(e)
isClickedOutside(isClickedInside.current, e) ? callback(e) : (isClickedInside.current = false)
}, {current: _document});

return useCallback(() => {
Expand Down

0 comments on commit 4e18b0a

Please sign in to comment.