File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,23 @@ const Search = ({ searchID }: { searchID?: string }): JSX.Element => {
2727 useEffect ( ( ) => {
2828 runDocsearchIfPossible ( )
2929
30+ const handleSearchTrigger = ( event : KeyboardEvent ) => {
31+ const slashKeyPressed = event . key === "/" || event . code === "Slash"
32+ if ( ! slashKeyPressed ) {
33+ return
34+ }
35+ event . preventDefault ( )
36+ const searchInput = document . querySelector < HTMLInputElement > (
37+ `#${ searchInputID } `
38+ )
39+
40+ if ( searchInput ) {
41+ searchInput . focus ( )
42+ }
43+ }
44+
45+ window . addEventListener ( "keypress" , handleSearchTrigger )
46+
3047 if ( document . getElementById ( "algolia-search" ) ) return
3148
3249 const searchScript = document . createElement ( "script" )
@@ -49,6 +66,10 @@ const Search = ({ searchID }: { searchID?: string }): JSX.Element => {
4966 }
5067
5168 document . body . appendChild ( searchScript )
69+
70+ return ( ) => {
71+ window . removeEventListener ( "keypress" , handleSearchTrigger )
72+ }
5273 } , [ ] )
5374
5475 return (
You can’t perform that action at this time.
0 commit comments