I'm trying to use React portal to render a portal, so I created two div. One for backdrop and one for actual portal inside index.html file.
<div id="backdrop-root"></div>
<div id="overlay-root"></div>
<div id="root"></div>
My Portal code:
const Backdrop = () => {
return <div className="backdrop" />;
};
const ModalOverlay = () => {
return (
<div css={NewTransactionPortalStyles} className="modal">
<Card>
<div className="modal-header">
<div>Create Transaction</div>
<div>
<XLg size={23} />
</div>
</div>
<div className="grid-styles">
<div> This is my Portal </div>
</div>
</Card>
</div>
);
};
export const NewTransactionPortal = () => {
return (
<div css={NewTransactionPortalStyles}>
{ReactDOM.createPortal(
<Backdrop />,
document.getElementById("backdrop-root")!
)}
{ReactDOM.createPortal(
<ModalOverlay transaction={[]} />,
document.getElementById("overlay-root")!
)}
</div>
);
CSS content:
export const NewTransactionPortalStyles = css`
.backdrop {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
z-index: 10;
background: rgba(0, 0, 0, 0.75);
}
.modal {
position: fixed;
top: 30vh;
left: 10%;
width: 60%;
height: 50%
z-index: 100;
overflow: hidden;
}
I don't know what is missing but my CSS class is not applying on my portal, I can see I'm able to target the div but not able to apply CSS on it, so as a result I'm not able to get the required result. I'm using emotion library for my CSS here.
