@@ -2,7 +2,7 @@ import { Autocomplete, Box, Stack, TextField } from '@mui/material';
22import Typography from '@mui/material/Typography' ;
33import SearchIcon from '@mui/icons-material/Search' ;
44import Grid from '@mui/material/Grid' ;
5- import { useState } from 'react' ;
5+ import { useEffect , useState } from 'react' ;
66import { DefinedTool } from '@tools/defineTool' ;
77import { filterTools , tools } from '@tools/index' ;
88import { useNavigate } from 'react-router-dom' ;
@@ -27,6 +27,7 @@ export default function Hero() {
2727 const [ filteredTools , setFilteredTools ] = useState < DefinedTool [ ] > (
2828 _ . shuffle ( tools )
2929 ) ;
30+ const [ pendingNavigation , setPendingNavigation ] = useState < boolean > ( false ) ;
3031 const navigate = useNavigate ( ) ;
3132 const handleInputChange = (
3233 event : React . ChangeEvent < { } > ,
@@ -35,6 +36,14 @@ export default function Hero() {
3536 setInputValue ( newInputValue ) ;
3637 setFilteredTools ( _ . shuffle ( filterTools ( tools , newInputValue ) ) ) ;
3738 } ;
39+
40+ useEffect ( ( ) => {
41+ if ( pendingNavigation && filteredTools . length > 0 ) {
42+ navigate ( '/' + filteredTools [ 0 ] . path ) ;
43+ setPendingNavigation ( false ) ;
44+ }
45+ } , [ pendingNavigation , filteredTools , navigate ] ) ;
46+
3847 return (
3948 < Box width = { { xs : '90%' , md : '80%' , lg : '60%' } } >
4049 < Stack mb = { 1 } direction = { 'row' } spacing = { 1 } justifyContent = { 'center' } >
@@ -94,6 +103,11 @@ export default function Hero() {
94103 </ Box >
95104 </ Box >
96105 ) }
106+ onKeyDown = { ( event ) => {
107+ if ( event . key === 'Enter' ) {
108+ setPendingNavigation ( true ) ;
109+ }
110+ } }
97111 />
98112 < Grid container spacing = { 2 } mt = { 2 } >
99113 { exampleTools . map ( ( tool ) => (
0 commit comments