@@ -9,14 +9,17 @@ function Search(menu) {
99
1010 document . addEventListener ( 'keydown' , this . documentKeydown . bind ( this ) ) ;
1111
12- this . $searchBox . addEventListener (
13- 'keydown' ,
14- debounce ( this . searchBoxKeydown . bind ( this ) , { stopPropagation : true } ) ,
15- ) ;
16- this . $searchBox . addEventListener (
17- 'keyup' ,
18- debounce ( this . searchBoxKeyup . bind ( this ) , { stopPropagation : true } ) ,
19- ) ;
12+ let requestHandleSearchBoxEvent = debounce ( this . handleSearchBoxEvent . bind ( this ) ) ;
13+
14+ this . $searchBox . addEventListener ( 'keydown' , e => {
15+ e . stopPropagation ( ) ;
16+ if ( e . key === 'Enter' ) e . preventDefault ( ) ;
17+ requestHandleSearchBoxEvent ( e ) ;
18+ } ) ;
19+ this . $searchBox . addEventListener ( 'input' , e => {
20+ e . stopPropagation ( ) ;
21+ requestHandleSearchBoxEvent ( e ) ;
22+ } ) ;
2023
2124 // Perform an initial search if the box is not empty.
2225 if ( this . $searchBox . value ) {
@@ -54,23 +57,15 @@ Search.prototype.documentKeydown = function (e) {
5457 }
5558} ;
5659
57- Search . prototype . searchBoxKeydown = function ( e ) {
58- e . stopPropagation ( ) ;
59- e . preventDefault ( ) ;
60- if ( e . keyCode === 191 && e . target . value . length === 0 ) {
61- e . preventDefault ( ) ;
62- } else if ( e . keyCode === 13 ) {
63- e . preventDefault ( ) ;
64- this . selectResult ( ) ;
65- }
66- } ;
67-
68- Search . prototype . searchBoxKeyup = function ( e ) {
69- if ( e . keyCode === 13 || e . keyCode === 9 ) {
70- return ;
60+ Search . prototype . handleSearchBoxEvent = function ( e ) {
61+ switch ( e . type ) {
62+ case 'keydown' :
63+ if ( e . key === 'Enter' ) this . selectResult ( ) ;
64+ break ;
65+ case 'input' :
66+ this . search ( e . target . value ) ;
67+ break ;
7168 }
72-
73- this . search ( e . target . value ) ;
7469} ;
7570
7671Search . prototype . triggerSearch = function ( ) {
0 commit comments