Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Dialog): use target-based backdrop detection for native popup compat (#1892)

Cindy Zhangd5a206ae9601
diff --git a/packages/core/src/Dialog/XDSDialog.tsx b/packages/core/src/Dialog/XDSDialog.tsx
index 173028f5db..a4f49d7ef6 100644
--- a/packages/core/src/Dialog/XDSDialog.tsx
+++ b/packages/core/src/Dialog/XDSDialog.tsx
@@ -436,20 +436,13 @@ export function XDSDialog({
return () => dialog.removeEventListener('keydown', handleKeyDown);
}, [isOpen, isInline, allowEscape, onOpenChange]);
- // Handle backdrop click
+ // Handle backdrop click — when the user clicks the ::backdrop pseudo-element,
+ // the event target is the <dialog> element itself; clicks on child content
+ // always target the child. This avoids false positives from native browser
+ // popups (date pickers, selects, color pickers) that render outside the
+ // dialog's bounding rect.
const handleClick = (event: React.MouseEvent<HTMLDialogElement>) => {
- const dialog = dialogRef.current;
- if (!dialog) return;
-
- // Check if click was on the backdrop (dialog element itself, not content)
- const rect = dialog.getBoundingClientRect();
- const isBackdropClick =
- event.clientX < rect.left ||
- event.clientX > rect.right ||
- event.clientY < rect.top ||
- event.clientY > rect.bottom;
-
- if (isBackdropClick && allowBackdropClick) {
+ if (event.target === event.currentTarget && allowBackdropClick) {
onOpenChange(false);
}
};