Dialog (Modal) with fixed height/width and scrollable content #412
-
Sometimes you want to use a modal as an "intermediate page" - situations where you show a lot of content, but don't want to switch routes. This could be done by having a huge modal (something like 3/4 screen height & width). Then, the content of the modal should be scrollable on the Y axis when there's not enough vertical space. Also, the header and footer of the modal (maybe a title at the top and some buttons at the bottom) are fixed/not scrolling. I tried to use the Dialog (Modal) in React with (Y-)scrollable content, but failed. My first thought is using Here's a CodeSandbox: https://codesandbox.io/s/naughty-water-22gmm?file=/src/App.tsx Is the only real solution to create a custom class? For example something like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hello @bennettdams, did you find a solution? I was trying to have a modal that is not covered on the entire screen and doesn't close if you click on e.g a navbar. Like you have it on the Modal picture. |
Beta Was this translation helpful? Give feedback.
-
I found a solution by giving the inner container of the modal a fixed (viewport) height: Then, the modal content has the automatic overflow: <Dialog
as="div"
id="modal"
className="fixed inset-0 z-10 overflow-y-auto"
static
>
<div className="min-h-screen">
<div
className={
"inline-flex flex-col overflow-hidden" +
` ${!widthFromContent && "w-full max-w-md"}`
}
style={{ maxHeight: "90vh" }}
>
<Dialog.Title as="div">...</Dialog.Title>
<Dialog.Description as="div" className="mt-4 w-full overflow-y-auto">
{children}
</Dialog.Description>
....
</div>
</div>
</Dialog> |
Beta Was this translation helpful? Give feedback.
I found a solution by giving the inner container of the modal a fixed (viewport) height:
style={{ maxHeight: "90vh" }}
(could also create a custom Tailwind class, of course).Then, the modal content has the automatic overflow: