Skip to content

Commit e107474

Browse files
victorneuretVladislavMedved
authored andcommitted
Add option to display suggestion on setInput
1 parent 2a87687 commit e107474

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

API.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ Set input
185185

186186
#### Parameters
187187

188-
* `searchInput` **[string][76]** location name or other search input
188+
* `searchInput` **[string][57]** location name or other search input
189+
- `showSuggestions` **[boolean][61]** display suggestion on setInput call (optional, default `false`)
189190

190191
Returns **[MapboxGeocoder][2]** this
191192

lib/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,15 +928,18 @@ MapboxGeocoder.prototype = {
928928
/**
929929
* Set input
930930
* @param {string} searchInput location name or other search input
931+
* @param {boolean} [showSuggestions=false] display suggestion on setInput call
931932
* @returns {MapboxGeocoder} this
932933
*/
933-
setInput: function(searchInput) {
934+
setInput: function(searchInput, showSuggestions = true) {
934935
// Set input value to passed value and clear everything else.
935936
this._inputEl.value = searchInput;
936937
this._typeahead.selected = null;
937938
this._typeahead.clear();
938-
if (searchInput.length >= this.options.minLength) {
939+
if (showSuggestions && searchInput.length >= this.options.minLength) {
939940
this._geocode(searchInput);
941+
} else if (!showSuggestions) {
942+
this._onChange();
940943
}
941944
return this;
942945
},

0 commit comments

Comments
 (0)