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 (
{/* 模态框 */}
搜索
@@ -144,6 +145,7 @@ export default function AlgoliaSearchModal({ cRef }) { placeholder="在这里输入搜索关键词..." onChange={e => handleInputChange(e)} className="text-black dark:text-gray-200 bg-gray-50 dark:bg-gray-600 outline-blue-500 w-full px-4 my-2 py-1 mb-4 border rounded-md" + ref={inputRef} /> {/* 标签组 */} @@ -197,20 +199,20 @@ function TagGroups(props) { const firstTenTags = tagOptions?.slice(0, 10) return
- { - firstTenTags?.map((tag, index) => { - return -
-
{tag.name}
{tag.count ? {tag.count} : <>} -
+ { + firstTenTags?.map((tag, index) => { + return +
+
{tag.name}
{tag.count ? {tag.count} : <>} +
- - }) - } -
+ + }) + } +
} /** @@ -229,7 +231,7 @@ function Pagination(props) { pagesElement.push(getPageElement(i, selected, switchPage)) } return
- {pagesElement.map(p => p)} + {pagesElement.map(p => p)}
}