| 11 | } |
| 12 | |
| 13 | export function ModalContent({ children, ...props }: ModalContentProps) { |
| 14 | const contentRef = useRef<HTMLDivElement>(null); |
| 15 | return ( |
| 16 | <DialogContent |
| 17 | {...props} |
| 18 | onPointerDownOutside={(e) => { |
| 19 | if (!contentRef.current) { |
| 20 | return; |
| 21 | } |
| 22 | const contentRect = contentRef.current.getBoundingClientRect(); |
| 23 | // Detect if click actually happened within the bounds of content. |
| 24 | // This can happen if click was on an absolutely positioned element overlapping content, |
| 25 | // such as the 1password extension icon in the text input. |
| 26 | const actuallyClickedInside = |
| 27 | e.detail.originalEvent.clientX > contentRect.left && |
| 28 | e.detail.originalEvent.clientX < |
| 29 | contentRect.left + contentRect.width && |
| 30 | e.detail.originalEvent.clientY > contentRect.top && |
| 31 | e.detail.originalEvent.clientY < contentRect.top + contentRect.height; |
| 32 | |
| 33 | if (actuallyClickedInside) { |
| 34 | e.preventDefault(); |
| 35 | } |
| 36 | |
| 37 | // Best for shadow DOM/web components (1Password uses this) |
| 38 | const path = e.detail.originalEvent.composedPath(); |
| 39 | const clicked1Password = path.some( |
| 40 | (node) => |
| 41 | node instanceof Element && |
| 42 | node.tagName.toLowerCase() === 'com-1password-button' |
| 43 | ); |
| 44 | if (clicked1Password) { |
| 45 | e.preventDefault(); |
| 46 | return; |
| 47 | } |
| 48 | }} |
| 49 | ref={contentRef} |
| 50 | > |
| 51 | {children} |
| 52 | </DialogContent> |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | interface ModalHeaderProps { |
| 57 | title: string | React.ReactNode; |