diff --git a/src/components/SearchBox.tsx b/src/components/SearchBox.tsx index cf932dab..bf7bdb89 100644 --- a/src/components/SearchBox.tsx +++ b/src/components/SearchBox.tsx @@ -1,15 +1,16 @@ "use client"; import { useState, useEffect, useRef } from "react"; import { Document as FlexSearchDocument } from "flexsearch"; -import { Search } from "lucide-react"; +import { Search, XIcon } from "lucide-react"; import { sva } from "styled-system/css"; +import { IconButton, Popover } from "@chakra-ui/react"; export type PostDocument = { - slug: string; - title: string; - date: string; - tags: string; - content: string; + slug: string; + title: string; + date: string; + tags: string; + content: string; }; // SVAでスタイルを定義 @@ -79,7 +80,6 @@ const searchBoxStyles = sva({ left: 0, right: 0, mt: "8px", - zIndex: 40, }, popoverContent: { maxH: "70vh", @@ -202,7 +202,7 @@ export const SearchBox = () => { // インデックスの初期化 useEffect(() => { if (typeof window === "undefined") return; - + async function initializeSearchIndex() { setIsLoading(true); try { @@ -264,7 +264,7 @@ export const SearchBox = () => { }); const allResults = new Map(); - + // 結果の処理 type EnrichedResult = { id: string; doc: PostDocument | null; highlight?: string }; type EnrichedDocumentSearchResult = { field?: keyof PostDocument; tag?: keyof PostDocument; result: EnrichedResult[] }; @@ -284,7 +284,7 @@ export const SearchBox = () => { const results = Array.from(allResults.values()); setSearchResults(results); - setIsOpen(results.length > 0); + setIsOpen(results.length > 0 || (inputRef.current?.value.length ?? 0) > 0); } catch (error) { console.error("検索処理中にエラーが発生しました:", error); } @@ -293,7 +293,7 @@ export const SearchBox = () => { // 検索結果のハイライト const highlightText = (text: string, query: string) => { if (!query.trim()) return text; - + try { const segments = text.split(new RegExp(`(${query})`, "gi")); return segments.map((segment, index) => @@ -342,35 +342,33 @@ export const SearchBox = () => { return (
-