Skip to content

Commit 57db1ee

Browse files
Fix very tall modals (#20041)
1 parent a3b04e4 commit 57db1ee

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

components/dashboard/src/components/Modal.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export const Modal: FC<Props> = ({
5454

5555
trackEvent("modal_dismiss", {
5656
manner,
57-
title: title,
58-
specify: specify,
57+
title,
58+
specify,
5959
path: window.location.pathname,
6060
});
6161
},
@@ -82,13 +82,19 @@ export const Modal: FC<Props> = ({
8282
tabIndex={0}
8383
>
8484
{/* Modal outer-container for positioning */}
85-
<div className="pointer-events-none relative h-[calc(100%-1rem)] w-auto min-[576px]:mx-auto min-[576px]:mt-7 min-[576px]:h-[calc(100%-3.5rem)] min-[576px]:max-w-[500px]">
85+
<div
86+
className={cn(
87+
"pointer-events-none relative",
88+
"h-dvh w-auto", // small screens
89+
"min-[576px]:mx-auto min-[576px]:mt-7 min-[576px]:h-[calc(100%-3.5rem)] min-[576px]:max-w-[500px]", // large screens
90+
)}
91+
>
8692
<FocusOn
8793
autoFocus={autoFocus}
8894
onClickOutside={handleClickOutside}
8995
onEscapeKey={handleEscape}
9096
focusLock={!disableFocusLock}
91-
className="relative max-h-[100%] w-full"
97+
className="relative max-h-full h-full w-full"
9298
>
9399
{/* Visible Modal */}
94100
<div
@@ -97,7 +103,7 @@ export const Modal: FC<Props> = ({
97103
"bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-800 outline-none",
98104
"p-6 text-left",
99105
"filter drop-shadow-xl",
100-
"rounded-none sm:rounded-xl",
106+
"rounded-none min-[576px]:rounded-xl",
101107
className,
102108
)}
103109
role="dialog"
@@ -143,11 +149,18 @@ const MaybeWithForm: FC<MaybeWithFormProps> = ({ onSubmit, disabled, children })
143149
);
144150

145151
if (!onSubmit) {
146-
return <>{children}</>;
152+
return (
153+
<div className="flex flex-col max-h-[calc(100dvh-3rem)] min-[576px]:max-h-[calc(100dvh-6rem)]">
154+
{children}
155+
</div>
156+
);
147157
}
148158

149159
return (
150-
<form onSubmit={handleSubmit}>
160+
<form
161+
onSubmit={handleSubmit}
162+
className="flex flex-col max-h-[calc(100dvh-3rem)] min-[576px]:max-h-[calc(100dvh-6rem)]"
163+
>
151164
{/* including a hidden submit button ensures submit on enter works despite a button w/ type="submit" existing or not */}
152165
<input type="submit" className="hidden" hidden disabled={disabled} />
153166
{children}
@@ -161,7 +174,7 @@ type ModalHeaderProps = {
161174

162175
export const ModalHeader: FC<ModalHeaderProps> = ({ children }) => {
163176
return (
164-
<Heading2 id="modal-header" className="pb-2">
177+
<Heading2 id="modal-header" className="pb-2 shrink-0">
165178
{children}
166179
</Heading2>
167180
);
@@ -177,7 +190,7 @@ export const ModalBody: FC<ModalBodyProps> = ({ children, hideDivider = false })
177190
// Allows the first tabbable element in the body to receive focus on mount
178191
<AutoFocusInside
179192
className={cn(
180-
"md:flex-grow relative border-gray-200 dark:border-gray-800 -mx-6 px-6 pb-6 overflow-y-auto",
193+
"flex-grow min-[576px]:flex-grow-0 relative border-gray-200 dark:border-gray-800 -mx-6 px-6 pb-6 overflow-y-auto",
181194
{
182195
"border-t border-b mt-2 py-4": !hideDivider,
183196
},
@@ -200,7 +213,7 @@ export const ModalFooter: FC<ModalFooterProps> = ({ className, alert, children }
200213
<div
201214
className={classNames(
202215
// causes footer to show up on top of alert
203-
"relative",
216+
"relative shrink-0",
204217
// make as wide as the modal so it covers the alert
205218
"-mx-6 -mb-6 p-6",
206219
// apply the same bg and rounded corners as the modal

0 commit comments

Comments
 (0)