From 33a1937407b214262e3e24d6567f347be7fc12d3 Mon Sep 17 00:00:00 2001 From: Bhwa233 <404174262@qq.com> Date: Fri, 1 Mar 2024 17:12:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=80=E5=BC=B9=E7=AA=97=E8=87=AA?= =?UTF-8?q?=E5=8A=A8focus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/AlgoliaSearchModal.js | 44 +++++++++++++++++--------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/components/AlgoliaSearchModal.js b/components/AlgoliaSearchModal.js index 26ed7d88..9eecf076 100644 --- a/components/AlgoliaSearchModal.js +++ b/components/AlgoliaSearchModal.js @@ -19,7 +19,7 @@ export default function AlgoliaSearchModal({ cRef }) { const [totalPage, setTotalPage] = useState(0) const [totalHit, setTotalHit] = useState(0) const [useTime, setUseTime] = useState(0) - + const inputRef = useRef(null) /** * 对外暴露方法 */ @@ -27,6 +27,9 @@ export default function AlgoliaSearchModal({ cRef }) { return { openSearch: () => { setIsModalOpen(true) + setTimeout(() => { + inputRef.current.focus() + }, 100) } } }) @@ -119,15 +122,13 @@ export default function AlgoliaSearchModal({ cRef }) { return (