From 6a5196f15570a50cef56f02f932fdbc6c2adbfbd Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Mon, 2 Jun 2025 18:27:05 +0100 Subject: [PATCH 1/2] [Docs Site] Add tags filter to /search/ --- src/components/search/InstantSearch.tsx | 59 +++++++++++++++++-------- src/styles/input.css | 22 ++++----- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/components/search/InstantSearch.tsx b/src/components/search/InstantSearch.tsx index 04055a549435ae7..59a046062449bde 100644 --- a/src/components/search/InstantSearch.tsx +++ b/src/components/search/InstantSearch.tsx @@ -90,12 +90,18 @@ function InfiniteHits(props: UseInfiniteHitsProps) { function FilterDropdown({ attribute, label, + limit = 1000, }: { attribute: string; label: string; + limit?: number; }) { const [isOpen, setIsOpen] = useState(false); - const { items, refine } = useRefinementList({ attribute }); + const { items, refine } = useRefinementList({ + attribute, + limit, + sortBy: ["count:desc"], + }); useEffect(() => { const params = new URLSearchParams(window.location.search); @@ -112,12 +118,19 @@ function FilterDropdown({ const refined = items .filter((item) => item.isRefined) .map((item) => item.value); - if (refined.length === 0) return; + + const params = new URLSearchParams(window.location.search); + + if (refined.length === 0) { + params.delete(attribute); + } else { + params.set(attribute, refined.join(",")); + } history.pushState( null, "", - `${window.location.pathname}?${attribute}=${refined.join(",")}`, + `${window.location.pathname}?${params.toString()}`, ); }, [items]); @@ -160,21 +173,28 @@ function FilterDropdown({ className="border-cl1-gray-8 bg-cl1-white dark:border-cl1-gray-1 dark:bg-cl1-gray-0 rounded-sm border p-4 shadow-md" >
- {items.map((item) => ( - - ))} + {items + .sort((a, b) => { + if (a.isRefined && !b.isRefined) return -1; + if (!a.isRefined && b.isRefined) return 1; + return b.count - a.count; + }) + .map((item) => ( + + ))}
@@ -198,8 +218,9 @@ export default function InstantSearchComponent() {
-
+
+
diff --git a/src/styles/input.css b/src/styles/input.css index ba7847b30dbdf10..df3167e6967e8b4 100644 --- a/src/styles/input.css +++ b/src/styles/input.css @@ -1,12 +1,14 @@ -input, -textarea, -select { - background-color: var(--sl-color-bg-nav); - border-color: var(--sl-color-gray-5); - border-width: 2px; -} +@layer theme { + input, + textarea, + select { + background-color: var(--sl-color-bg-nav); + border-color: var(--sl-color-gray-5); + border-width: 2px; + } -input[readonly] { - background-color: var(--sl-color-backdrop-overlay); - cursor: not-allowed; + input[readonly] { + background-color: var(--sl-color-backdrop-overlay); + cursor: not-allowed; + } } From c4a2f2c4e2705f7741b93732e9f6c5a69b728db6 Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Tue, 3 Jun 2025 13:18:18 +0100 Subject: [PATCH 2/2] sync query too --- src/components/search/InstantSearch.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/components/search/InstantSearch.tsx b/src/components/search/InstantSearch.tsx index 59a046062449bde..cbb40dfc21de44b 100644 --- a/src/components/search/InstantSearch.tsx +++ b/src/components/search/InstantSearch.tsx @@ -34,6 +34,22 @@ function SearchBox(props: UseSearchBoxProps) { } }, []); + useEffect(() => { + const params = new URLSearchParams(window.location.search); + + if (query) { + params.set("q", query); + } else { + params.delete("q"); + } + + history.pushState( + null, + "", + `${window.location.pathname}?${params.toString()}`, + ); + }, [query]); + return (