diff --git a/packages/client/src/components/OriginalDialog.tsx b/packages/client/src/components/OriginalDialog.tsx index 74e67c60fd..5a472940ce 100644 --- a/packages/client/src/components/OriginalDialog.tsx +++ b/packages/client/src/components/OriginalDialog.tsx @@ -78,29 +78,24 @@ 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( (event: KeyboardEvent) => { const tooltips = document.querySelectorAll('.tooltip'); + const dropdownMenus = document.querySelectorAll('[role="menu"]'); - 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; - } + if (tooltips.length > 0) { + event.preventDefault(); + return; + } + + if (dropdownMenus.length > 0) { + event.preventDefault(); + return; } - // Call the original handler if it exists propsOnEscapeKeyDown?.(event); }, [propsOnEscapeKeyDown],