-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Nested portals should be discoverable #14540
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution. |
With the React.Flare deprecation this issue is still very valuable. |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Sorry StaleBot, but we need some solution. |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you! |
Bump. It would be great to have a solution to this. |
I think this is still relevant so re-opening. I've seen the recommendation to use Would be interesting to check if Since we don't have the tools to introspect the React tree (and I think it was made clear that we never will have), we currently don't truly now if the currentTarget of a React event contains the target of a React event. This is relevant for focus-trapping but I think so far we've been able to fix it in userland? So it would be nice to create a comprehensive list of |
Bump. We have the same issue and it's really annoying. Nested portals are a pretty reasonable thing, and there is no way to tell if an event originated from a nested child portal. For example, a modal (portal) with a dropdown (portal) inside it. If I click outside the modal, both should close. If I click the inner dropdown, the outer modal should stay open. However, the outer modal thinks the inner click is an external dom node, so it closes. We are solving this by adding a Context wrapper around our portals which passes down a setter that each child portal can call in order to save its node in the parent. It works, but this feels really silly since React KNOWS that these are parent/child in the virtual dom. Being locked out of the virtual dom's knowledge feels really bad here. Edit: And before anyone says "don't use portals," please trust that we have good reasons for this and portals are the best solution for our use case. |
I also ended up managing portals from the user space via ContextApi/subscriptions, but while such solution works perfectly - it works perfectly only for me and cannot be shared with some third-party library as it is "not standard". |
This is more about a bridge between actual DOM Tree and React Tree.
Do you want to request a feature or report a bug?
feature
What is the current behavior?
You can portal a part of your rendering tree to another place in Dom Tree, and React would handle events, including events on Capture Phase like there were no portals - events could dive through all the react parents, and bubble up through all the react parents.
This is quite useful, as long as portal is an implementation detail, but useful only for normal events; there are more cases around it.
What is the expected behavior?
It's better to explain it by example
ModalNode.contains(DropDownNode)
is always false, and Focus Lock will prevent focusing.It's a real issue - reach/reach-ui#83, theKashey/react-focus-lock#19.
Proposed solution:
containsNode(domNode):boolean
- React-aware version of DOM APInode.contains(anotherNode)
.getHostNodes():Nodes[]
- returns a list of all root nodes inside "current component" including direct children and portals. Similar toReactDom.findDomNode
, and (proposed)refs attached to React.Fragment. It just finds all nodes "you are consists of". As a result you will be able totab
from onepiece
of you to another, making focus management independed of implementation details.Cons:
hook
to do it in a functional way.findDomNode
Pros:
findDomNode
, where underlaying node might not be yet created. Stuff like "does somethingcontainsNode
right now", or "getHostNodes
I consist from right now" are sync, and the question asked about actual DOM tree structure.Example using react-dom-reflection, which implements required API - https://codesandbox.io/s/1or60v506l
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Never worked
The text was updated successfully, but these errors were encountered: