Portal: Add PortalProvider for default container context#3812
Open
rxliuli wants to merge 2 commits intoradix-ui:mainfrom
Open
Portal: Add PortalProvider for default container context#3812rxliuli wants to merge 2 commits intoradix-ui:mainfrom
rxliuli wants to merge 2 commits intoradix-ui:mainfrom
Conversation
When using Radix components inside a Shadow DOM, every portal-based component needs a custom `container` prop. This adds a `PortalProvider` context so users can set the default portal container once at the top level, and all nested Portal components automatically use it. Priority chain: explicit `container` prop > PortalProvider context > document.body Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
PortalProvidercomponent to@radix-ui/react-portal, allowing users to set a default portal container via React context. This is particularly useful for browser extensions and Shadow DOM scenarios, where portaling todocument.bodybreaks style isolation.Without
PortalProvider, every portal-based component (Dialog, Popover, Tooltip, Select, Menu, etc.) needs an explicitcontainerprop — tedious and error-prone. Now users can set it once at the top level:Container priority: explicit
containerprop >PortalProvidercontext >document.bodyNo changes needed to downstream components — they all pass
containerthrough toPortal, soundefinednow falls back to context automatically.Related issues
Test plan
pnpm typecheckpassespnpm buildpassespnpm lintpassesdocument.bodyby default (no PortalProvider)containerprop on Portal overrides PortalProvider🤖 Generated with Claude Code