diff --git a/components/SearchInput.js b/components/SearchInput.js index 715c0d70..005bded0 100644 --- a/components/SearchInput.js +++ b/components/SearchInput.js @@ -1,15 +1,22 @@ import { useRouter } from 'next/router' import { useGlobal } from '@/lib/global' -import { useRef, useState } from 'react' +import { useImperativeHandle, useRef, useState } from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faSearch, faSpinner, faTimes } from '@fortawesome/free-solid-svg-icons' -const SearchInput = ({ currentTag, currentSearch }) => { +const SearchInput = ({ currentTag, currentSearch, cRef }) => { const { locale } = useGlobal() const [searchKey, setSearchKey] = useState(currentSearch) const [onLoading, setLoadingState] = useState(false) const router = useRouter() const searchInputRef = useRef() + useImperativeHandle(cRef, () => { + return { + focus: () => { + searchInputRef?.current?.focus() + } + } + }) const handleSearch = (key) => { if (key && key !== '') { setLoadingState(true)