Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add use-detect-outside-click hook #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

luisdralves
Copy link
Contributor

@luisdralves luisdralves commented Jul 15, 2022

This PRs adds the use-detect-outside-click hook. It detects if a click is inside or outside a component

target instanceof Element &&
!ref?.current?.contains(target)
) {
setActive(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be more beneficial if this was a callback?
Usually a click outside is an action, when we click outside an element, we want to trigger a callback.
For example, a simple modal or a dropdown menu, clicking outside those elements would trigger a close.

Suggested change
setActive(false);
callback();

I'm not seeing a good case for using a state @luisdralves, but maybe you have a more explicit example.
WDYT @rafaelcruzazevedo?

@rafaelcruzazevedo rafaelcruzazevedo removed their assignment Jul 14, 2023
@rafaelcruzazevedo rafaelcruzazevedo removed their request for review August 7, 2023 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hooks Regarding the `hooks` package type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants