diff --git a/packages/client/src/components/OriginalDialog.tsx b/packages/client/src/components/OriginalDialog.tsx index 206cca87fe..8f59d690c3 100644 --- a/packages/client/src/components/OriginalDialog.tsx +++ b/packages/client/src/components/OriginalDialog.tsx @@ -78,7 +78,7 @@ const DialogContent = React.forwardRef< }, ref, ) => { - /* Handle Escape key to prevent closing dialog if a tooltip is open + /* Handle Escape key to prevent closing dialog if a tooltip or dropdown 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( @@ -100,6 +100,22 @@ const DialogContent = React.forwardRef< } } + // Check if a dropdown menu is open + const dropdownMenus = document.querySelectorAll('[role="menu"]'); + for (const dropdown of Array.from(dropdownMenus)) { + const computedStyle = window.getComputedStyle(dropdown); + const opacity = parseFloat(computedStyle.opacity); + + if ( + computedStyle.display !== 'none' && + computedStyle.visibility !== 'hidden' && + opacity > 0 + ) { + event.preventDefault(); + return; + } + } + // Call the original handler if it exists propsOnEscapeKeyDown?.(event); },