Skip to content

[Bug] Dialog - Portal's container prop does not change the portal #3599

Open
@etn-tech

Description

@etn-tech

Bug report

Current Behavior

The container prop of Dialog.Portal does not update the portal.

When opening the dialog, the body tag is still the element used for the portal element (See Stackblitz demo)

Code snippets

App.tsx :
Image

DialogDemo.tsx :
Image

Browser screenshots

Page before dialog open :

Image Image

Page after dialog open :

Image

Expected behavior

The div#root should be used as a the portal element. style="pointer-events: none;" & data-scroll-locked="&" should be on div#root.
The data-radix-focus-guards should be in div#root.

Reproducible example

Stackblitz demo

Suggested solution

In primitive/portal, we might check mounted is true
before containerProp.

// Before 
const container = containerProp || (mounted && globalThis?.document?.body);
// After 
const container = mounted && (containerProp || globalThis?.document?.body);

Not sure if it will be sufficient to fix the bug...

Additional context

Your environment

See Stackblitz demo

Software Name(s) Version
Radix Package(s)
React 19.1.0
Browser Chrome 137.0
Assistive tech
Node n/a
npm/yarn/pnpm npm 10.8.2
Operating System macOS 15.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions