Skip to content

Commit

Permalink
Set focus on field after clear.
Browse files Browse the repository at this point in the history
  • Loading branch information
sherakama committed Oct 23, 2024
1 parent 3ff09bf commit ceb5d95
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/search/Modal/SearchFieldModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const SearchFieldModal = React.forwardRef(({ emptySearchMessage }, ref) => {
const debouncedInputValue = useDebouncedValue(inputValue);
const [options, setOptions] = useState([]);
const [showEmptyMessage, setShowEmptyMessage] = useState(false);
const { close } = useContext(SearchModalContext);
const { close, modalSearchInputRef } = useContext(SearchModalContext);

// Debounce the input value and fetch options.
// -------------------------------------------
Expand Down Expand Up @@ -103,7 +103,8 @@ const SearchFieldModal = React.forwardRef(({ emptySearchMessage }, ref) => {
const handleClear = useCallback(() => {
setInputValue('');
setValue('');
}, [setInputValue, setValue]);
modalSearchInputRef.current.focus();
}, [setInputValue, setValue, modalSearchInputRef]);

// Render the search field.
// ------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/components/search/SearchField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ const SearchField = ({ emptySearchMessage }) => {
setInputValue('');
setValue('');
refine('');
}, [setInputValue, setValue, refine]);
searchInputRef.current.focus();
}, [setInputValue, setValue, refine, searchInputRef]);

// The search field component.
// ---------------------------
Expand Down

0 comments on commit ceb5d95

Please sign in to comment.