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

Unexpected useClickOutside behavior - popover doesn't close #3143

Closed
geodn opened this issue Dec 8, 2022 · 2 comments
Closed

Unexpected useClickOutside behavior - popover doesn't close #3143

geodn opened this issue Dec 8, 2022 · 2 comments
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@geodn
Copy link

geodn commented Dec 8, 2022

What package has an issue

@mantine/hooks

Describe the bug

I'm using a mantine Popover that opens when I click a button in a table. However, when I click below the table, the popover doesn't close. I investigated a bit and found that shouldIgnore ends up being true within the listeners attached by useClickOutside. This happens because the click event target is the whole page, from <html> to </html>, and this target is not considered part of document.body. Thus, the outside click is ignored.

Screenshot 2022-12-07 at 10 12 03 PM

This is unexpected, right? At least, I'd like for the popover to close when I click below the table. The close behavior works anywhere else on the page, where the click event target does end up as part of document.body

What version of @mantine/hooks page do you have in package.json?

5.8.4

If possible, please include a link to a codesandbox with the reproduced problem

No response

Do you know how to fix the issue

None

Are you willing to participate in fixing this issue and create a pull request with the fix

None

Possible fix

Adjust computation of shouldIgnore. But I'm not sure what the cleanest way to do so would be. I confirmed that removing the document.body.contains(target) check works, but I'm assuming that was put there for a reason?

@rtivital
Copy link
Member

rtivital commented Dec 8, 2022

I think we can simply check whether the target is html element and adjust the logic to exclude it from shouldIgnore

@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Dec 12, 2022
rtivital added a commit that referenced this issue Dec 12, 2022
@rtivital
Copy link
Member

Fixed in 5.9.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

2 participants