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,
) => {
/* 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],