Skip to content

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

@luisdralves luisdralves force-pushed the feature/use-detect-outside-click branch from 3bd8862 to 38ee5d5 Compare July 15, 2022 14:00
@luisdralves luisdralves requested a review from andrewmoreno July 15, 2022 14:01
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.

5 participants