File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
packages/gitbook/src/components/Search Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -55,10 +55,6 @@ export function SearchModal(props: SearchModalProps) {
55
55
} ;
56
56
} , [ isSearchOpened ] ) ;
57
57
58
- // if (state === null) {
59
- // return null;
60
- // }
61
-
62
58
const onChangeQuery = ( newQuery : SearchState ) => {
63
59
setSearchState ( newQuery ) ;
64
60
} ;
@@ -170,10 +166,21 @@ function SearchModalBody(
170
166
inputRef . current ?. focus ( ) ;
171
167
} , [ ] ) ;
172
168
169
+ React . useEffect ( ( ) => {
170
+ const handleKeyDown = ( event : KeyboardEvent ) => {
171
+ if ( event . key === 'Escape' ) {
172
+ onClose ( ) ;
173
+ }
174
+ } ;
175
+ document . addEventListener ( 'keydown' , handleKeyDown ) ;
176
+
177
+ return ( ) => {
178
+ document . removeEventListener ( 'keydown' , handleKeyDown ) ;
179
+ } ;
180
+ } , [ onClose ] ) ;
181
+
173
182
const onKeyDown = ( event : React . KeyboardEvent < HTMLInputElement > ) => {
174
- if ( event . key === 'Escape' ) {
175
- onClose ( ) ;
176
- } else if ( event . key === 'ArrowUp' ) {
183
+ if ( event . key === 'ArrowUp' ) {
177
184
event . preventDefault ( ) ;
178
185
resultsRef . current ?. moveUp ( ) ;
179
186
} else if ( event . key === 'ArrowDown' ) {
You can’t perform that action at this time.
0 commit comments