@@ -37,7 +37,7 @@ export function Search({
3737 const [ query , setQuery ] = useState ( router . query . query || '' )
3838 const [ results , setResults ] = useState < Array < SearchResult > > ( [ ] )
3939 const [ isLoading , setIsLoading ] = useState ( false )
40- const [ activeHit , setActiveHit ] = useState ( 0 )
40+ const [ activeHit , setActiveHit ] = useState ( - 1 )
4141 const inputRef = useRef < HTMLInputElement > ( null )
4242 const { t } = useTranslation ( 'search' )
4343 const { currentVersion } = useVersion ( )
@@ -164,55 +164,53 @@ export function Search({
164164 < div
165165 id = "search-results-container"
166166 className = { cx (
167- 'z-1' ,
167+ 'z-1 pb-4 px-3 ' ,
168168 styles . resultsContainer ,
169169 isOverlay && styles . resultsContainerOverlay ,
170170 query && styles . resultsContainerOpen
171171 ) }
172172 >
173173 { results . length > 0 ? (
174- < ol data-testid = "search-results" className = "d-block" >
175- { results . map ( ( { url, breadcrumbs, heading, title, content } , index ) => (
176- < li
177- key = { url }
178- data-testid = "search-result"
179- className = { cx (
180- 'list-style-none overflow-hidden hover:color-bg-info' ,
181- index + 1 === activeHit && 'color-bg-info'
182- ) }
183- >
184- < div className = "border-top color-border-secondary py-3 px-2" >
185- < a className = "no-underline" href = { url } >
186- { /* Breadcrumbs in search records don't include the page title. These fields may contain <mark> elements that we need to render */ }
187- < div
188- className = "d-block color-text-primary opacity-60 text-small pb-1"
189- dangerouslySetInnerHTML = { { __html : breadcrumbs } }
190- />
191- < div
192- className = { cx (
193- styles . searchResultTitle ,
194- 'd-block f4 font-weight-semibold color-text-primary'
195- ) }
196- dangerouslySetInnerHTML = { {
197- __html : heading ? `${ title } : ${ heading } ` : title ,
198- } }
199- />
200- < div
201- className = { cx (
202- styles . searchResultContent ,
203- 'd-block color-text-secondary overflow-hidden'
204- ) }
205- style = { { maxHeight : '4rem' } }
206- dangerouslySetInnerHTML = { { __html : content } }
207- />
208- </ a >
209- </ div >
210- </ li >
211- ) ) }
174+ < ol data-testid = "search-results" className = "d-block mt-2" >
175+ { results . map ( ( { url, breadcrumbs, heading, title, content } , index ) => {
176+ const isActive = index === activeHit
177+ return (
178+ < li
179+ key = { url }
180+ data-testid = "search-result"
181+ className = { cx (
182+ 'list-style-none overflow-hidden rounded-3 color-text-primary border' ,
183+ isActive ? 'color-bg-tertiary' : 'color-border-transparent'
184+ ) }
185+ onMouseEnter = { ( ) => setActiveHit ( index ) }
186+ >
187+ < div className = { cx ( 'py-3 px-3' , isActive && 'color-border-secondary' ) } >
188+ < a className = "no-underline color-text-primary" href = { url } >
189+ { /* Breadcrumbs in search records don't include the page title. These fields may contain <mark> elements that we need to render */ }
190+ < div
191+ className = { 'd-block opacity-60 text-small pb-1' }
192+ dangerouslySetInnerHTML = { { __html : breadcrumbs } }
193+ />
194+ < div
195+ className = { cx ( styles . searchResultTitle , 'd-block f4 font-weight-semibold' ) }
196+ dangerouslySetInnerHTML = { {
197+ __html : heading ? `${ title } : ${ heading } ` : title ,
198+ } }
199+ />
200+ < div
201+ className = { cx ( styles . searchResultContent , 'd-block overflow-hidden' ) }
202+ style = { { maxHeight : '4rem' } }
203+ dangerouslySetInnerHTML = { { __html : content } }
204+ />
205+ </ a >
206+ </ div >
207+ </ li >
208+ )
209+ } ) }
212210 </ ol >
213211 ) : (
214212 isOverlay && (
215- < div className = "mt-2" >
213+ < div className = "mt-2 px-6 " >
216214 { isLoading ? < span > { t ( 'loading' ) } ...</ span > : < span > { t ( 'no_results' ) } .</ span > }
217215 </ div >
218216 )
0 commit comments