fix: docs search resets on result click (#419)

This commit is contained in:
Daniel Lautzenheiser 2023-01-23 15:34:22 -05:00 committed by GitHub
parent f360cdaaa9
commit 6f79fdd3ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,18 +87,20 @@ const SearchModal: FC<SearchModalProps> = ({ open, onClose, searchablePages }) =
const [canFocus, setCanFocus] = useState(true);
const [search, setSearch] = useState('');
const handleFocus = () => {
const handleFocus = useCallback(() => {
if (canFocus && open && inputRef.current) {
inputRef.current?.focus();
setSearch('');
setCanFocus(false);
}
};
}, [canFocus, open]);
const handleClose = useCallback(() => {
setCanFocus(true);
setTimeout(() => {
onClose();
setTimeout(() => {
setCanFocus(true);
}, 100);
}, 100);
}, [onClose]);