From 6727ae4eb275756e3e387e27dac09d633ed385a9 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 11 Jan 2022 16:07:40 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E8=BE=93=E5=85=A5=E6=A1=86=E8=81=9A?= =?UTF-8?q?=E7=84=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/SearchInput.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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)