Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat(react): blurred modal backdrop that does not darken when dialogs stack (#1896)

Brad Barbinaa5a8a032e9a
diff --git a/packages/config/tailwind/theme.css b/packages/config/tailwind/theme.css
index 41d90f5542..a181990af5 100644
--- a/packages/config/tailwind/theme.css
+++ b/packages/config/tailwind/theme.css
@@ -435,3 +435,35 @@
white-space: nowrap;
}
}
+
+/*
+ * Stacked dialogs. Every dialog backdrop carries `data-backdrop`, and only the
+ * top-most OPEN one paints: a modal opened over a modal or a drawer dims and
+ * blurs the page and the dialog beneath it once, instead of once per layer.
+ * DOM order is stacking order — Radix portals append to <body> as they open.
+ * The covered backdrop fades out while the new one fades in, and back again
+ * as it closes (a closing backdrop is `data-state=closed` and stops covering).
+ * Unlayered, so it outranks the overlays' own background/blur utilities.
+ */
+[data-backdrop] {
+ transition:
+ background-color 150ms,
+ -webkit-backdrop-filter 150ms,
+ backdrop-filter 150ms;
+}
+
+body
+ > [data-backdrop]:has(
+ ~ [data-backdrop][data-state="open"],
+ ~ * [data-backdrop][data-state="open"]
+ ),
+body
+ > :has(
+ ~ [data-backdrop][data-state="open"],
+ ~ * [data-backdrop][data-state="open"]
+ )
+ [data-backdrop] {
+ background-color: transparent;
+ -webkit-backdrop-filter: none;
+ backdrop-filter: none;
+}
diff --git a/packages/react/src/BottomSheet.tsx b/packages/react/src/BottomSheet.tsx
index 1210058950..97d29b398b 100644
--- a/packages/react/src/BottomSheet.tsx
+++ b/packages/react/src/BottomSheet.tsx
@@ -40,6 +40,7 @@ const BottomSheetOverlay = forwardRef<
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
+ data-backdrop=""
className={cn(
"fixed inset-0 z-[70] bg-black/40 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
diff --git a/packages/react/src/Dock.tsx b/packages/react/src/Dock.tsx
index 3725db9e63..65ea508a59 100644
--- a/packages/react/src/Dock.tsx
+++ b/packages/react/src/Dock.tsx
@@ -140,7 +140,10 @@ const DockMenuContent = forwardRef<
<ClientOnly fallback={null}>
{() => (
<DialogPrimitive.Portal>
- <DialogPrimitive.Overlay className="fixed inset-0 z-[70] bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0" />
+ <DialogPrimitive.Overlay
+ data-backdrop=""
+ className="fixed inset-0 z-[70] bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"
+ />
{/* The content spans the screen's width, but only its parts take
touches: a tap in the gaps between them lands on the overlay,
which closes the menu like any tap outside. */}
diff --git a/packages/react/src/Drawer.tsx b/packages/react/src/Drawer.tsx
index 1873a52c54..ad988f5647 100644
--- a/packages/react/src/Drawer.tsx
+++ b/packages/react/src/Drawer.tsx
@@ -68,6 +68,7 @@ const DrawerOverlay = forwardRef<
ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, children, ...props }, ref) => (
<DialogPrimitive.Overlay
+ data-backdrop=""
className={cn(
"fixed inset-0 z-50 bg-black/20 max-md:bg-black/40 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
diff --git a/packages/react/src/Modal.tsx b/packages/react/src/Modal.tsx
index fffc97dcc9..765a4e51f4 100644
--- a/packages/react/src/Modal.tsx
+++ b/packages/react/src/Modal.tsx
@@ -53,13 +53,14 @@ const ModalOverlay = forwardRef<
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
+ // Only the top-most backdrop paints, so stacked modals keep one level of
+ // dim (see `[data-backdrop]` in the shared theme.css).
+ data-backdrop=""
className={cn(
- // 'z-50 fixed h-full w-full left-0 top-0',
- // 'bg-alternative/90 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
- "bg-alternative/90",
+ "bg-black/40 backdrop-blur-xs",
"z-50 fixed inset-0 grid place-items-center overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=closed]:animate-out data-[state=closed]:fade-out-0",
// Phones: a bottom sheet over a dimmed screen.
- "max-md:place-items-end max-md:overflow-hidden max-md:bg-black/40",
+ "max-md:place-items-end max-md:overflow-hidden",
className
)}