fix(path-input): improve keydown handling

- Updated keydown event logic to prevent search activation when input fields or contenteditable elements are focused.
- Enhanced ESC key handling to ensure parent modal does not close when search is open.
- Adjusted dependencies in useEffect to include entries length for better state management.
This commit is contained in:
Illia Filippov
2025-12-25 02:39:42 +01:00
parent fd51abb3ce
commit a7de6406ed

View File

@@ -217,7 +217,8 @@ function PathInput({
e.key === '/' &&
!isEditing &&
!isSearchOpen &&
!(e.target as HTMLElement).matches('input, textarea')
entries.length > 0 &&
!(e.target as HTMLElement).matches('input, textarea, [contenteditable="true"]')
) {
e.preventDefault();
setIsSearchOpen(true);
@@ -225,14 +226,13 @@ function PathInput({
// Close search with Escape key
if (e.key === 'Escape' && isSearchOpen) {
e.preventDefault();
e.stopPropagation(); // Prevent parent modal from closing
setIsSearchOpen(false);
}
};
window.addEventListener('keydown', handleGlobalKeyDown, true); // Use capture phase
window.addEventListener('keydown', handleGlobalKeyDown, true); // Use capture phase for ESC handling and prevent parent modal from closing when search is open
return () => window.removeEventListener('keydown', handleGlobalKeyDown, true);
}, [isEditing, isSearchOpen]);
}, [isEditing, isSearchOpen, entries.length]);
// Close search when clicking outside
useEffect(() => {