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

OutsideClick only works in the context of a single DOM tree #20

Closed
sgb-io opened this issue Oct 10, 2018 · 7 comments
Closed

OutsideClick only works in the context of a single DOM tree #20

sgb-io opened this issue Oct 10, 2018 · 7 comments

Comments

@sgb-io
Copy link
Contributor

sgb-io commented Oct 10, 2018

The technique used in this library for the OutsideClick component is closely coupled to the DOM. The technique used in this library only works in the context of a single DOM tree. This is a problem if you want to apply <OutsideClick> around a portal (imagine a context menu that appears next to a users mouse click, for example).

If you render something inside it that contains a portal, it breaks:

Uncaught TypeError: _this.el.contains is not a function
    at HTMLDocument.OutsideClick._this.onClickOutside

A potential different, more decoupled approach, would be to make use of onBlur on the OutsideClick component, tracking if the user is clicking it or something else via hover detection, but this would mean one ends up with a radically different solution.

@streamich
Copy link
Owner

Thank for the info, if you would like to implement that, PRs are welcome.

@sgb-io
Copy link
Contributor Author

sgb-io commented Oct 10, 2018

Actually this is solvable by adding a new prop to the component such as clickRoot, which allows the user to override this.el

@sgb-io sgb-io changed the title OutsideClick is too coupled to the DOM OutsideClick only works in the context of a single DOM tree Oct 12, 2018
@IssueHuntBot
Copy link

@BoostIO funded this issue with $20. Visit this issue on Issuehunt

@IssueHuntBot
Copy link

@sgb-io has started working. Visit this issue on Issuehunt

@IssueHuntBot
Copy link

@sgb-io has submitted output. Visit this issue on Issuehunt

@sgb-io
Copy link
Contributor Author

sgb-io commented Oct 17, 2018

See #22 - working solution that solves the issue by adding a new clickRoots prop

@sgb-io
Copy link
Contributor Author

sgb-io commented Oct 22, 2018

Resolved by #22

@sgb-io sgb-io closed this as completed Oct 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants