This commit is contained in:
Dustin Healy 2025-12-15 16:22:26 -08:00 committed by GitHub
commit be7d21703e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -78,29 +78,24 @@ const DialogContent = React.forwardRef<
}, },
ref, 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 (this is a workaround in order to achieve WCAG compliance which requires
that our tooltips be dismissable with Escape key) */ that our tooltips be dismissable with Escape key) */
const handleEscapeKeyDown = React.useCallback( const handleEscapeKeyDown = React.useCallback(
(event: KeyboardEvent) => { (event: KeyboardEvent) => {
const tooltips = document.querySelectorAll('.tooltip'); const tooltips = document.querySelectorAll('.tooltip');
const dropdownMenus = document.querySelectorAll('[role="menu"]');
for (const tooltip of Array.from(tooltips)) { if (tooltips.length > 0) {
const computedStyle = window.getComputedStyle(tooltip); event.preventDefault();
const opacity = parseFloat(computedStyle.opacity); return;
}
if (
tooltip.parentElement && if (dropdownMenus.length > 0) {
computedStyle.display !== 'none' && event.preventDefault();
computedStyle.visibility !== 'hidden' && return;
opacity > 0
) {
event.preventDefault();
return;
}
} }
// Call the original handler if it exists
propsOnEscapeKeyDown?.(event); propsOnEscapeKeyDown?.(event);
}, },
[propsOnEscapeKeyDown], [propsOnEscapeKeyDown],