Skip to content

Commit 4fdefe5

Browse files
feat(ui): clear gallery search on esc key
1 parent 9870f5a commit 4fdefe5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

invokeai/frontend/web/src/features/gallery/components/ImageGrid/GallerySearch.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IconButton, Input, InputGroup, InputRightElement, Spinner } from '@invoke-ai/ui-library';
22
import { useAppSelector } from 'app/store/storeHooks';
33
import { selectListImagesQueryArgs } from 'features/gallery/store/gallerySelectors';
4-
import type { ChangeEvent } from 'react';
4+
import type { ChangeEvent, KeyboardEvent } from 'react';
55
import { useCallback } from 'react';
66
import { useTranslation } from 'react-i18next';
77
import { PiXBold } from 'react-icons/pi';
@@ -27,13 +27,24 @@ export const GallerySearch = ({ searchTerm, onChangeSearchTerm, onResetSearchTer
2727
[onChangeSearchTerm]
2828
);
2929

30+
const handleKeydown = useCallback(
31+
(e: KeyboardEvent<HTMLInputElement>) => {
32+
// exit search mode on escape
33+
if (e.key === 'Escape') {
34+
onResetSearchTerm();
35+
}
36+
},
37+
[onResetSearchTerm]
38+
);
39+
3040
return (
3141
<InputGroup>
3242
<Input
3343
placeholder={t('gallery.searchImages')}
3444
value={searchTerm}
3545
onChange={handleChangeInput}
3646
data-testid="image-search-input"
47+
onKeyDown={handleKeydown}
3748
/>
3849
{isPending && (
3950
<InputRightElement h="full" pe={2}>

0 commit comments

Comments
 (0)