question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Portal] Explore giving more control for layering

See original GitHub issue

We currently apply the maximum z-index on portals and have had a few requests to allow more control here. This ticket is to explore ways of allowing that for a few reasons:

  • People have requested it
  • Can only override all portal instances via the data-radix-portal attribute atm
  • Other Radix components provide an API to control things (consistency)
  • The data-radix-portal attribute is an inconsistent escape hatch that we removed from other comps

An initial discussion on this topic provided a couple ideas:

  • A layer/zIndex prop for portalled parts, e.g. <DialogContent layer={3}>
  • ~A Portal provider part exposed per component that provides its props to the internal portal, e.g. <DialogPortal style={{ zIndex: 3 }}><DialogContent /></DialogPortal>. The provider suggestion is because we need control internally of how/where/when the portal is rendered.~
  • Expose a Portal part for people to wrap when they want portals, e.g. Dialog.Portal. Examples.
  • Use Slot internally on the Portal. This would reduce elements rendered as an additional win but it wouldn’t work with:
    • Popper based parts because popper wraps its own additional div for positioning
    • Parts that use https://github.com/theKashey/react-remove-scroll because portal needs to wrap the RemoveScroll part for it to work, and RemoveScroll isn’t slot-aware.
  • Any more for any more?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:11
  • Comments:26 (10 by maintainers)

github_iconTop GitHub Comments

9reactions
jjenzzcommented, Oct 26, 2021

We’ve published a release candidate for this in Dialog and AlertDialog to try. The API has breaking changes with this change so we would love feedback on the approach before we roll it out across our other components.

The new anatomy is as follows:

<Dialog.Root>
  <Dialog.Trigger />
  <Dialog.Portal>
    <Dialog.Overlay />
    <Dialog.Content />
  </Dialog.Portal>
</Dialog.Root>

Note:

  • The Dialog.Content can be rendered inside Dialog.Overlay if preferred for styling purposes.
  • The Dialog.Portal doesn’t render a div anymore so z-index styles can be applied to Dialog.Overlay/Dialog.Content directly.
  • The Dialog.Portal can portal into a custom container using the container prop:
     const [container, setContainer] = React.useState(null);
     
     return (
       <>
         <Dialog.Root>
           <Dialog.Trigger />
           <Dialog.Portal container={container}>
             <Dialog.Overlay />
             <Dialog.Content />
           </Dialog.Portal>
         </Dialog.Root>
         <div ref={setContainer} />
       </>
     );
    
5reactions
pdongcommented, Oct 22, 2021

Having more control here would be really helpful. My use-case is that I’m using react-toastify to show toasts; on mobile I’m using modals as full-page takeovers and sometimes want to show a toast over it. I can use Portal to put my toasts above everything but since they’re always max z-index as soon as the overlay and modal mount they’re always on top of the toasts. Having a little wiggle room here would be helpful.

I think exposing Portal in the Dialog primitive makes sense and will allow more control over how the Dialog renders. It’s definitely a little more overhead but not much more than having to compose all the other parts anyway and will give developers much more control over how things behave.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manage hosted web layers—Portal for ArcGIS
You control the following for your hosted web layers: ... Add, update, and delete features gives editors the most privileges of the three...
Read more >
Protect Assets with Layered Commercial Security Access ...
In this post, we'll examine the three main access control methods and how they work together to create a layered business security system....
Read more >
Configure pop-ups—Portal for ArcGIS
Open the map in Map Viewer, click Details, and click Contents. Browse to the sublayer that contains the feature data you want to...
Read more >
Known issues | App Layering - Citrix Product Documentation
When you enable an image with elastic layering, users might be able to view files and directories from other sessions in Windows Explorer....
Read more >
What is Machine Learning? | IBM
A neural network that consists of more than three layers—which would be ... Economic Area, giving individuals more control of their data.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found