mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 08:20:14 +01:00
refactor: simplify escapekeydown handler logic for tooltips and dropdown menus
This commit is contained in:
parent
df1765c48e
commit
d4327173c7
1 changed files with 8 additions and 29 deletions
|
|
@ -84,39 +84,18 @@ const DialogContent = React.forwardRef<
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
if (tooltips.length > 0) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
if (dropdownMenus.length > 0) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// Call the original handler if it exists
|
||||
propsOnEscapeKeyDown?.(event);
|
||||
},
|
||||
[propsOnEscapeKeyDown],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue