I need to implement a Popover primitive that always appear on top of all other elements in the page, I tried to see if some well known solutions have this implemented but it seems in all cases the Popover is added to the bottom of the Page but still z-index is still in use:
For example:
Implementing a simple Popover is not that difficult but doing it with plain CSS might have the same issues as the ones above
- It might need
z-indexto be set in most cases - It might not be correctly positioned if its position is
fixedand it is inside a container that have a css transform, since a new stacking context might have been created. - It might be shown inside a container with overflow auto or hidden.
Despite those issues a CSS only popover offers a very simple API and it is very easy to create.
Here is an example of the simple API I'm looking for
// the Overlay is a controlled component so the
// fact that is shown or not is controlled by the
// open property
<CSSOverlay open={isOpen}>
<div>Content here</div>
</CSSOverlay>
But most of the examples I've found go for something like
<SomeOverlay open={isOpen} style={{ zIndex: 100000 /* some arbitrary hight number no other popover will use, or at least we hope it won't */ }}>
<div>Content here</div>
</SomeOverlay>
or appending it to the body, which might still have z-index issues, and now might also have issues accessing content inside React Providers as context might not be shared with it
<SomeOverlay open={isOpen} appendToBody={true}>
<div>Content here</div>
</SomeOverlay>
Here is an example of a the CSS Popover with z-index issues
Full disclosure: This is a re-write of a now closed question posted here: What are the downsides or potential drawbacks of using `popover` attribute to create overlays, like tooltips, popovers and dialogs I've modified