open-amdocs / webrix

Powerful building blocks for React-based web applications
https://webrix.amdocs.com
Apache License 2.0
432 stars 32 forks source link

`useClickOutside` - added `options` argument to the hook #103

Closed yairEO closed 2 years ago

yairEO commented 2 years ago
const useClickOutside = (callback, options)

Added options optional argument (Object) to useClickOutside:

target

control over mousedown/mouseup event handlers target (beside the document).

For example, in React the whole app resides with a wrapper element and not directly <body> so the target options could be set to something like document.querySelector('#root') and so, if any "portaled" element (on the body) would not be considered as a "click outside".

condition

Before this change, the only way to bypass the isClickedOutside condition (defined within the context) was to wrap the component with <ClickOutsideOverride> and pass a condition prop.

If a functional component is using the useClickOutside hook, it is easier to pass an argument than to wrap the JSX with a context provider (ClickOutsideOverride).

codecov[bot] commented 2 years ago

Codecov Report

Base: 96.00% // Head: 95.90% // Decreases project coverage by -0.10% :warning:

Coverage data is based on head (4ac0afb) compared to base (06660f1). Patch coverage: 80.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #103 +/- ## ========================================== - Coverage 96.00% 95.90% -0.11% ========================================== Files 61 61 Lines 852 855 +3 Branches 29 29 ========================================== + Hits 818 820 +2 - Misses 33 34 +1 Partials 1 1 ``` | [Impacted Files](https://codecov.io/gh/open-amdocs/webrix/pull/103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-amdocs) | Coverage Δ | | |---|---|---| | [src/hooks/useClickOutside/useClickOutside.js](https://codecov.io/gh/open-amdocs/webrix/pull/103/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-amdocs#diff-c3JjL2hvb2tzL3VzZUNsaWNrT3V0c2lkZS91c2VDbGlja091dHNpZGUuanM=) | `77.77% <80.00%> (-2.23%)` | :arrow_down: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-amdocs). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-amdocs)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

yairEO commented 2 years ago

I've changed my mind - no need for this