Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable debounce delay #436

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ A geocoder component using the [Mapbox Geocoding API][67]
- `options.fuzzyMatch` **[Boolean][73]** Specify whether the Geocoding API should attempt approximate, as well as exact, matching when performing searches, or whether it should opt out of this behavior and only attempt exact matching. (optional, default `true`)
- `options.routing` **[Boolean][73]** Specify whether to request additional metadata about the recommended navigation destination corresponding to the feature or not. Only applicable for address features. (optional, default `false`)
- `options.worldview` **[String][69]** Filter results to geographic features whose characteristics are defined differently by audiences belonging to various regional, cultural, or political groups. (optional, default `"us"`)
- `options.debounceDelay` **[Number][72]** Specify the input debounce delay (in milliseconds). (optional, default `200`)

### Examples

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## master

### Features / Improvements 🚀

- Configurable debounce delay [#436](https://github.com/mapbox/mapbox-gl-geocoder/pull/436)

## 4.7.4

### Features / Improvements 🚀
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const GEOCODE_REQUEST_TYPE = {
* @param {Boolean} [options.fuzzyMatch=true] Specify whether the Geocoding API should attempt approximate, as well as exact, matching when performing searches, or whether it should opt out of this behavior and only attempt exact matching.
* @param {Boolean} [options.routing=false] Specify whether to request additional metadata about the recommended navigation destination corresponding to the feature or not. Only applicable for address features.
* @param {String} [options.worldview="us"] Filter results to geographic features whose characteristics are defined differently by audiences belonging to various regional, cultural, or political groups.
* @param {Number} [options.debounceDelay=200] Specify the input debounce delay (in milliseconds).
* @example
* var geocoder = new MapboxGeocoder({ accessToken: mapboxgl.accessToken });
* map.addControl(geocoder);
Expand Down Expand Up @@ -93,6 +94,7 @@ MapboxGeocoder.prototype = {
collapsed: false,
clearAndBlurOnEsc: false,
clearOnBlur: false,
debounceDelay: 200,
getItemValue: function(item) {
return item.place_name
},
Expand Down Expand Up @@ -214,7 +216,7 @@ MapboxGeocoder.prototype = {
this._inputEl.addEventListener('blur', this._onBlur);
}

this._inputEl.addEventListener('keydown', debounce(this._onKeyDown, 200));
this._inputEl.addEventListener('keydown', debounce(this._onKeyDown, this.options.debounceDelay));
this._inputEl.addEventListener('paste', this._onPaste);
this._inputEl.addEventListener('change', this._onChange);
this.container.addEventListener('mouseenter', this._showButton);
Expand Down