Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

💄 Scroll dialogs as a whole instead of their content (#3549)

Luke Vellaa074a6939f4e
diff --git a/packages/tailwind-config/shared-styles.css b/packages/tailwind-config/shared-styles.css
index 6fa44daa4..39045421d 100644
--- a/packages/tailwind-config/shared-styles.css
+++ b/packages/tailwind-config/shared-styles.css
@@ -2,8 +2,8 @@
@custom-variant dark (&:where(.dark, .dark *));
/* A dialog header or footer at the top level of the dialog's scroll area
- * (directly, or inside a top-level form or wizard step), where it pins to
- * the edge. */
+ * (directly, or inside a top-level form or wizard step), where it spans the
+ * dialog's edges. */
@custom-variant dialog-edge (:is(
[data-slot="dialog-scroller"],
[data-slot="dialog-scroller"] > form,
diff --git a/packages/ui/src/dialog.tsx b/packages/ui/src/dialog.tsx
index ca652d9ca..5812a78a1 100644
--- a/packages/ui/src/dialog.tsx
+++ b/packages/ui/src/dialog.tsx
@@ -49,7 +49,7 @@ function DialogOverlay({
const dialogVariants = cva(
cn(
- "data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 fixed top-[50%] left-[50%] z-50 flex max-h-[calc(100dvh-2rem)] w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] flex-col overflow-hidden rounded-2xl border border-popover-border bg-popover shadow-lg outline-none duration-200 data-closed:animate-out data-open:animate-in",
+ "data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 relative my-auto flex w-full shrink-0 flex-col overflow-hidden rounded-2xl border border-popover-border bg-popover shadow-lg outline-none duration-200 data-closed:animate-out data-open:animate-in",
),
{
variants: {
@@ -82,25 +82,29 @@ function DialogContent({
return (
<DialogPortal data-slot="dialog-portal">
<DialogOverlay />
- <DialogPrimitive.Popup
- data-slot="dialog-content"
- className={cn(dialogVariants({ size }), className)}
- data-close-button={showCloseButton ? "" : undefined}
- {...props}
+ {/* A dialog taller than the screen scrolls as one card inside the
+ viewport rather than scrolling its own content. */}
+ <DialogPrimitive.Viewport
+ data-slot="dialog-viewport"
+ className="fixed inset-0 z-50 flex flex-col items-center overflow-y-auto overscroll-contain p-4"
>
- <div
- data-slot="dialog-scroller"
- className="grid min-h-0 grow gap-4 overflow-y-auto overscroll-contain p-4"
+ <DialogPrimitive.Popup
+ data-slot="dialog-content"
+ className={cn(dialogVariants({ size }), className)}
+ data-close-button={showCloseButton ? "" : undefined}
+ {...props}
>
- {children}
- </div>
- {showCloseButton && (
- <DialogClose className="absolute top-4 right-4 z-20 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0">
- <XIcon />
- <span className="sr-only">Close</span>
- </DialogClose>
- )}
- </DialogPrimitive.Popup>
+ <div data-slot="dialog-scroller" className="grid gap-4 p-4">
+ {children}
+ </div>
+ {showCloseButton && (
+ <DialogClose className="absolute top-4 right-4 z-20 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0">
+ <XIcon />
+ <span className="sr-only">Close</span>
+ </DialogClose>
+ )}
+ </DialogPrimitive.Popup>
+ </DialogPrimitive.Viewport>
</DialogPortal>
);
}
@@ -110,7 +114,7 @@ function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
<div
data-slot="dialog-header"
className={cn(
- "dialog-edge:sticky dialog-edge:-top-4 dialog-edge:z-10 dialog-edge:-mx-4 dialog-edge:-mt-4 dialog-edge:bg-popover dialog-edge:px-4 dialog-edge:pt-4 dialog-edge:pb-2",
+ "dialog-edge:pb-2",
// Only the first row sits beside the close button.
"dialog-edge:in-data-close-button:*:first:pr-8",
className,
@@ -126,7 +130,7 @@ function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
data-slot="dialog-footer"
className={cn(
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
- "dialog-edge:sticky dialog-edge:-bottom-4 dialog-edge:z-10 dialog-edge:-mx-4 dialog-edge:mt-2 dialog-edge:-mb-4 dialog-edge:border-popover-border dialog-edge:border-t dialog-edge:bg-card dialog-edge:px-4 dialog-edge:py-3",
+ "dialog-edge:-mx-4 dialog-edge:mt-2 dialog-edge:-mb-4 dialog-edge:border-popover-border dialog-edge:border-t dialog-edge:bg-card dialog-edge:px-4 dialog-edge:py-3",
className,
)}
{...props}