@@ -17,25 +17,23 @@ const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
1717</a >
1818
1919<!-- Search Input -->
20- <div class =" relative" style = " margin: 1rem var(--sl-sidebar-item-padding-inline) 0.75rem; " >
20+ <div class =" relative" >
2121 <input
2222 type =" text"
2323 id =" sidebar-search"
2424 placeholder =" Search documentation..."
2525 class =" w-full px-3 pr-8 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-orange-500 dark:focus:border-orange-500 transition-colors duration-200"
2626 />
27- <button
28- id =" sidebar-search-clear"
29- class =" absolute right-2 top-1/2 transform -translate-y-1/2 bg-transparent border-none text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 cursor-pointer text-xl leading-none p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors duration-200"
30- style =" display: none;"
27+ <button
28+ id =" sidebar-search-clear"
29+ class =" absolute right-2 top-1/2 transform -translate-y-1/2 bg-transparent border-none text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 cursor-pointer text-xl leading-none p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors duration-200"
3130 >×</button >
3231</div >
3332
3433<!-- No Results Message -->
35- <div
36- id =" sidebar-no-results"
37- class =" text-sm text-gray-500 dark:text-gray-400 text-center py-4 px-4 hidden"
38- style =" margin: 0 var(--sl-sidebar-item-padding-inline);"
34+ <div
35+ id =" sidebar-no-results"
36+ class =" text-sm text-gray-500 dark:text-gray-400 text-center p-4 hidden"
3937>
4038 No results found. Try a different search term, or use our <button id =" global-search-link" class =" text-blue-500 dark:text-orange-500 underline hover:no-underline cursor-pointer bg-transparent border-none p-0 font-inherit" >global search</button >.
4139</div >
@@ -49,7 +47,7 @@ const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
4947 const noResultsMessage = document.getElementById('sidebar-no-results') as HTMLElement;
5048 const globalSearchLink = document.getElementById('global-search-link') as HTMLButtonElement;
5149 const sidebarContent = document.querySelector('.sidebar-content');
52-
50+
5351 if (!searchInput || !sidebarContent || !noResultsMessage || !globalSearchLink) return;
5452
5553 const originalState: Map<Element, boolean> = new Map();
@@ -107,24 +105,24 @@ const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
107105 items.forEach(item => {
108106 (item as HTMLElement).style.display = '';
109107 });
110-
108+
111109 // Restore original details state
112110 detailsElements.forEach(details => {
113111 const originalOpen = originalState.get(details);
114112 if (originalOpen !== undefined) {
115113 (details as HTMLDetailsElement).open = originalOpen;
116114 }
117115 });
118-
116+
119117 // Hide no results message
120118 noResultsMessage.classList.add('hidden');
121-
119+
122120 clearButton.style.display = 'none';
123121 return;
124122 }
125123
126124 clearButton.style.display = 'block';
127-
125+
128126 // Split search query into terms for more precise matching
129127 const searchTerms = query.toLowerCase().split(/\s+/).filter(term => term.length > 0);
130128
@@ -144,7 +142,7 @@ const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
144142 const summary = details.querySelector('summary');
145143 if (summary) {
146144 const summaryText = summary.textContent || '';
147-
145+
148146 if (matchesAllTerms(summaryText, searchTerms)) {
149147 // This is a folder match - show the folder and its direct children
150148 const parentLi = details.closest('li');
@@ -161,16 +159,16 @@ const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
161159 // 2. Check for specific page matches (show page + parent chain)
162160 items.forEach(item => {
163161 if (matchedItems.has(item)) return; // Skip if already matched as folder
164-
162+
165163 const link = item.querySelector('a');
166164 const summary = item.querySelector('summary');
167-
165+
168166 // Skip if this is a folder (has summary) - those are handled above
169167 if (summary) return;
170-
168+
171169 if (link) {
172170 const linkText = link.textContent || '';
173-
171+
174172 if (matchesAllTerms(linkText, searchTerms)) {
175173 // This is a specific page match - show page + parent chain
176174 (item as HTMLElement).style.display = '';
@@ -190,21 +188,21 @@ const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
190188 const summaryText = summary?.textContent?.toLowerCase() || '';
191189
192190 // Check if any search term is found (partial matching)
193- const hasPartialMatch = searchTerms.some(term =>
191+ const hasPartialMatch = searchTerms.some(term =>
194192 textContent.includes(term) || linkText.includes(term) || summaryText.includes(term)
195193 );
196194
197195 if (hasPartialMatch) {
198196 (item as HTMLElement).style.display = '';
199-
197+
200198 // If it's a folder, show direct children only
201199 if (summary) {
202200 const details = item.querySelector('details');
203201 if (details) {
204202 showDirectChildren(details);
205203 }
206204 }
207-
205+
208206 showParentChain(item);
209207 matchedItems.add(item);
210208 }
@@ -248,17 +246,17 @@ const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
248246 const docSearchButton = document.querySelector('#docsearch button') as HTMLButtonElement ||
249247 document.querySelector('.DocSearch-Button') as HTMLButtonElement ||
250248 document.querySelector('[data-docsearch-button]') as HTMLButtonElement;
251-
249+
252250 if (docSearchButton) {
253251 // Click the DocSearch button to open the modal
254252 docSearchButton.click();
255-
253+
256254 // Wait for modal to open and set the search term
257255 setTimeout(() => {
258256 const searchInput = document.querySelector('.DocSearch-Input') as HTMLInputElement ||
259257 document.querySelector('#docsearch-input') as HTMLInputElement ||
260258 document.querySelector('[data-docsearch-input]') as HTMLInputElement;
261-
259+
262260 if (searchInput) {
263261 searchInput.value = currentQuery;
264262 searchInput.focus();
@@ -279,7 +277,7 @@ const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
279277 }
280278
281279 // Re-initialize on navigation (for SPA-like behavior)
282- document.addEventListener('astro:page-load', initSidebarSearch);
280+ initSidebarSearch( );
283281</script >
284282
285283<style is:global >
0 commit comments