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) {
5555 } ;
5656 } , [ isSearchOpened ] ) ;
5757
58- // if (state === null) {
59- // return null;
60- // }
61-
6258 const onChangeQuery = ( newQuery : SearchState ) => {
6359 setSearchState ( newQuery ) ;
6460 } ;
@@ -170,10 +166,21 @@ function SearchModalBody(
170166 inputRef . current ?. focus ( ) ;
171167 } , [ ] ) ;
172168
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+
173182 const onKeyDown = ( event : React . KeyboardEvent < HTMLInputElement > ) => {
174- if ( event . key === 'Escape' ) {
175- onClose ( ) ;
176- } else if ( event . key === 'ArrowUp' ) {
183+ if ( event . key === 'ArrowUp' ) {
177184 event . preventDefault ( ) ;
178185 resultsRef . current ?. moveUp ( ) ;
179186 } else if ( event . key === 'ArrowDown' ) {
You can’t perform that action at this time.
0 commit comments