@@ -98,7 +98,7 @@ MapboxGeocoder.prototype = {
98
98
this . _inputEl . type = 'text' ;
99
99
this . _inputEl . placeholder = this . _getPlaceholderText ( ) ;
100
100
101
- this . _inputEl . addEventListener ( 'keydown' , this . _onKeyDown ) ;
101
+ this . _inputEl . addEventListener ( 'keydown' , debounce ( this . _onKeyDown , 200 ) ) ;
102
102
this . _inputEl . addEventListener ( 'change' , this . _onChange ) ;
103
103
104
104
var actions = document . createElement ( 'div' ) ;
@@ -148,16 +148,17 @@ MapboxGeocoder.prototype = {
148
148
return this ;
149
149
} ,
150
150
151
- _onKeyDown : debounce ( function ( e ) {
152
-
151
+ _onKeyDown : function ( e ) {
152
+
153
153
// if target has shadowRoot, then get the actual active element inside the shadowRoot
154
- var target = e . target . shadowRoot
154
+ var target = e . target && e . target . shadowRoot
155
155
? e . target . shadowRoot . activeElement
156
156
: e . target ;
157
- if ( ! target . value ) {
157
+ var value = target ? target . value : '' ;
158
+ if ( ! value ) {
158
159
this . fresh = true ;
159
160
// the user has removed all the text
160
- this . _clear ( e ) ;
161
+ if ( e . keyCode !== 9 ) this . _clear ( e ) ;
161
162
return ( this . _clearEl . style . display = 'none' ) ;
162
163
}
163
164
@@ -168,7 +169,7 @@ MapboxGeocoder.prototype = {
168
169
if ( target . value . length >= this . options . minLength ) {
169
170
this . _geocode ( target . value ) ;
170
171
}
171
- } , 200 ) ,
172
+ } ,
172
173
173
174
_onChange : function ( ) {
174
175
if ( this . _inputEl . value ) this . _clearEl . style . display = 'block' ;
@@ -399,23 +400,23 @@ MapboxGeocoder.prototype = {
399
400
400
401
/**
401
402
* Get the language to use in UI elements and when making search requests
402
- *
403
+ *
403
404
* Look first at the explicitly set options otherwise use the browser's language settings
404
- *
405
+ *
405
406
* @returns {String } The language used by the geocoder
406
407
*/
407
408
getLanguage : function ( ) {
408
409
var browserLocale = navigator . language || navigator . userLanguage || navigator . browserLanguage ;
409
410
return this . options . language || browserLocale ;
410
411
} ,
411
412
412
- /**
413
+ /**
413
414
* Get the text to use as the search bar placeholder
414
- *
415
+ *
415
416
* If placeholder is provided in options, then use options.placeholder
416
417
* Otherwise, if language is provided in options, then use the localized string of the first language if available
417
418
* Otherwise use the default
418
- *
419
+ *
419
420
* @returns {String } the value to use as the search bar placeholder
420
421
* @private
421
422
*/
0 commit comments