diff --git a/packages/client/src/components/OriginalDialog.tsx b/packages/client/src/components/OriginalDialog.tsx index 08f6ef6bba..206cca87fe 100644 --- a/packages/client/src/components/OriginalDialog.tsx +++ b/packages/client/src/components/OriginalDialog.tsx @@ -66,28 +66,71 @@ type DialogContentProps = React.ComponentPropsWithoutRef, DialogContentProps ->(({ className, overlayClassName, showCloseButton = true, children, ...props }, ref) => ( - - - - {children} - {showCloseButton && ( - - - )} - - -)); +>( + ( + { + className, + overlayClassName, + showCloseButton = true, + children, + onEscapeKeyDown: propsOnEscapeKeyDown, + ...props + }, + ref, + ) => { + /* Handle Escape key to prevent closing dialog if a tooltip is open + (this is a workaround in order to achieve WCAG compliance which requires + that our tooltips be dismissable with Escape key) */ + const handleEscapeKeyDown = React.useCallback( + (event: KeyboardEvent) => { + const tooltips = document.querySelectorAll('.tooltip'); + + for (const tooltip of Array.from(tooltips)) { + const computedStyle = window.getComputedStyle(tooltip); + const opacity = parseFloat(computedStyle.opacity); + + if ( + tooltip.parentElement && + computedStyle.display !== 'none' && + computedStyle.visibility !== 'hidden' && + opacity > 0 + ) { + event.preventDefault(); + return; + } + } + + // Call the original handler if it exists + propsOnEscapeKeyDown?.(event); + }, + [propsOnEscapeKeyDown], + ); + + return ( + + + + {children} + {showCloseButton && ( + + + )} + + + ); + }, +); DialogContent.displayName = DialogPrimitive.Content.displayName; const DialogHeader = ({ className, ...props }: React.HTMLAttributes) => (