Skip to content

Dialog (Modal) with fixed height/width and scrollable content #412

Answered by bennettdams
bennettdams asked this question in Help
Discussion options

You must be logged in to vote

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:

<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

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@bennettdams
Comment options

Comment options

You must be logged in to vote
5 replies
@andyscraven
Comment options

@Jasperrr91
Comment options

@rosshabe
Comment options

@nhanitk14dev
Comment options

@BrunoTAlcantara
Comment options

Answer selected by bennettdams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
7 participants