@@ -23,11 +23,11 @@ export function Search(): JSX.Element {
2323 scope : scope || drive ,
2424 } ) ;
2525 const navigate = useNavigate ( ) ;
26- const htmlElRef = useRef < HTMLDivElement | null > ( null ) ;
26+ const resultsDiv = useRef < HTMLDivElement | null > ( null ) ;
2727
2828 function selectResult ( index : number ) {
2929 setSelected ( index ) ;
30- const currentElm = htmlElRef ?. current ?. children [ index ] ;
30+ const currentElm = resultsDiv ?. current ?. children [ index ] ;
3131 currentElm ?. scrollIntoView ( { block : 'nearest' } ) ;
3232 }
3333
@@ -36,7 +36,7 @@ export function Search(): JSX.Element {
3636 e => {
3737 e . preventDefault ( ) ;
3838 const subject =
39- htmlElRef ?. current ?. children [ selectedIndex ] ?. getAttribute ( 'about' ) ;
39+ resultsDiv ?. current ?. children [ selectedIndex ] ?. getAttribute ( 'about' ) ;
4040
4141 if ( subject ) {
4242 //@ts -ignore blur does exist though
@@ -80,9 +80,10 @@ export function Search(): JSX.Element {
8080 }
8181
8282 return (
83- < ContainerNarrow ref = { htmlElRef } >
84- { error && < ErrorLook > { error . message } </ ErrorLook > }
85- { query ?. length !== 0 && results . length !== 0 ? (
83+ < ContainerNarrow >
84+ { error ? (
85+ < ErrorLook > { error . message } </ ErrorLook >
86+ ) : query ?. length !== 0 && results . length !== 0 ? (
8687 < >
8788 < Heading >
8889 < FaSearch />
@@ -91,15 +92,17 @@ export function Search(): JSX.Element {
9192 < QueryText > { query } </ QueryText >
9293 </ span >
9394 </ Heading >
94- { results . map ( ( subject , index ) => (
95- < ResourceCard
96- initialInView = { index < 5 }
97- small
98- subject = { subject }
99- key = { subject }
100- highlight = { index === selectedIndex }
101- />
102- ) ) }
95+ < div ref = { resultsDiv } >
96+ { results . map ( ( subject , index ) => (
97+ < ResourceCard
98+ initialInView = { index < 5 }
99+ small
100+ subject = { subject }
101+ key = { subject }
102+ highlight = { index === selectedIndex }
103+ />
104+ ) ) }
105+ </ div >
103106 </ >
104107 ) : (
105108 < > { message } </ >
0 commit comments