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 => {
27
27
useEffect ( ( ) => {
28
28
runDocsearchIfPossible ( )
29
29
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
+
30
47
if ( document . getElementById ( "algolia-search" ) ) return
31
48
32
49
const searchScript = document . createElement ( "script" )
@@ -49,6 +66,10 @@ const Search = ({ searchID }: { searchID?: string }): JSX.Element => {
49
66
}
50
67
51
68
document . body . appendChild ( searchScript )
69
+
70
+ return ( ) => {
71
+ window . removeEventListener ( "keypress" , handleSearchTrigger )
72
+ }
52
73
} , [ ] )
53
74
54
75
return (
You can’t perform that action at this time.
0 commit comments