Skip to content

Commit

Permalink
Merge pull request #104 from open-amdocs/useClickOutside-should-call-…
Browse files Browse the repository at this point in the history
…the-override-condition-on-mouseup

`isClickedOutside` override (optional) condition to also fire on `mouseup`
  • Loading branch information
rafmim committed Oct 2, 2022
2 parents 06660f1 + e12d937 commit 4931ee7
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 4931ee7

Please sign in to comment.