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

[core] feat(Portal): Add portalContainer context option #6260

Merged
merged 11 commits into from
Jul 10, 2023

Conversation

braeden
Copy link
Contributor

@braeden braeden commented Jul 3, 2023

Fixes #6210

Checklist

  • Includes tests
  • Update documentation

Changes proposed in this pull request:

This changes forces all (blueprint) children that who render below a given PortalProvider (like <Dialog/>, <Popover2/>) to have a common element where React.createPortal usages become direct children of.

To be more precise here, portalContainer acts ONLY as a parent element of a new div and that new div becomes the target container in the React.createPortal syntax -- so children are rendered into that element.

We also memoize the PortalProvider value to avoid thrashing on every re-render.

Reviewers should focus on:

  • I changed the way that addStopPropagationListeners, removeStopPropagationListeners (and maybeAddClass) work -- using React.useEffect's cleanup function to avoid leaving, what I believe would have been, dangling listeners when the portal unmounted.
  • I removed the hasMounted state, since it was purely duplicative with portalElement != null
  • I removed Portal.defaultProps and replaces it with an internal ?? document?.body fallback.

Screenshot

Copy link
Contributor

@adidahiya adidahiya left a comment

Choose a reason for hiding this comment

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

looks good! just need a few documentation fixes

return container;
}, [props.className, context.portalClassName]);
return newPortalElement;
}, [className, context.portalClassName, legacyContext.blueprintPortalClassName, stopPropagationEvents]);
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, thanks for fixing this dependency list

@adidahiya adidahiya changed the title Add portalContainer option to to PortalContext/PortalProvider [core] feat(Portal): Add portalContainer context option Jul 6, 2023
@adidahiya
Copy link
Contributor

Another docs suggestion: let's update the link to React context docs. This line:

__Portal__ supports some customization through [React context](https://reactjs.org/docs/context.html).

Should instead point to: https://react.dev/learn/passing-data-deeply-with-context

Copy link
Contributor

@adidahiya adidahiya left a comment

Choose a reason for hiding this comment

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

thanks @braeden 👍🏽

@adidahiya adidahiya merged commit 5ae5f7d into palantir:develop Jul 10, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

Adding portalContainer to PortalContext/PortalProvider
2 participants