Skip to content

Commit

Permalink
Update to suggestions list (#14)
Browse files Browse the repository at this point in the history
* chore: update to use suggestions-list library

* chore: change default to enable showResultMarkers
  • Loading branch information
thaddmt authored Oct 28, 2021
1 parent 27fbdbb commit 72a3f02
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## master

- Switch from `suggestions` library to `suggestions-list`, change enter key logic to support selecting list items with enter key

## 1.1.1

### Features / Improvements 🚀
Expand Down
9 changes: 6 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var Typeahead = require("suggestions");
var Typeahead = require("suggestions-list");
var debounce = require("lodash.debounce");
var extend = require("xtend");
var EventEmitter = require("events").EventEmitter;
Expand Down Expand Up @@ -112,7 +112,7 @@ MaplibreGeocoder.prototype = {
"</div></div>"
);
},
showResultMarkers: false,
showResultMarkers: true,
debounceSearch: 200,
},

Expand Down Expand Up @@ -231,6 +231,7 @@ MaplibreGeocoder.prototype = {
this._inputEl.addEventListener("blur", this._onBlur);
}


this._inputEl.addEventListener("keydown", debounce(this._onKeyDown, this.options.debounceSearch));
this._inputEl.addEventListener("paste", this._onPaste);
this._inputEl.addEventListener("change", this._onChange);
Expand Down Expand Up @@ -271,6 +272,7 @@ MaplibreGeocoder.prototype = {
filter: false,
minLength: this.options.minLength,
limit: this.options.limit,
noInitialSelection: true,
});

this.setRenderFunction(this.options.render);
Expand Down Expand Up @@ -381,7 +383,8 @@ MaplibreGeocoder.prototype = {
// ENTER
if (e.keyCode === 13) {
if (!this.options.showResultsWhileTyping) {
this._geocode(target.value);
if (!this._typeahead.list.selectingListItem)
this._geocode(target.value);
} else {
if (this.options.showResultMarkers) {
this._fitBoundsForMarkers();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"lodash.debounce": "^4.0.6",
"nanoid": "^2.0.1",
"subtag": "^0.5.0",
"suggestions": "^1.6.0",
"suggestions-list": "^0.0.2",
"xtend": "^4.0.1"
},
"lint-staged": {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7695,10 +7695,10 @@ subtag@^0.5.0:
resolved "https://registry.yarnpkg.com/subtag/-/subtag-0.5.0.tgz#1728a8df5257fb98ded4fb981b2ac7af10cf58ba"
integrity sha512-CaIBcTSb/nyk4xiiSOtZYz1B+F12ZxW8NEp54CdT+84vmh/h4sUnHGC6+KQXUfED8u22PQjCYWfZny8d2ELXwg==

suggestions@^1.6.0:
version "1.7.1"
resolved "https://registry.yarnpkg.com/suggestions/-/suggestions-1.7.1.tgz#2fefcbde8967353056d1d6eaed891b46d98a7e5c"
integrity sha512-gl5YPAhPYl07JZ5obiD9nTZsg4SyZswAQU/NNtnYiSnFkI3+ZHuXAiEsYm7AaZ71E0LXSFaGVaulGSWN3Gd71A==
suggestions-list@^0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/suggestions-list/-/suggestions-list-0.0.2.tgz#3c5f501833e697a726a1bf58fbc454d57ffa0e98"
integrity sha512-Yw0fdq14c6RQWQIfE1/8WEi9Dp8rjyCD6FhYA/Tit2/ADbE9Y4ADG4ezlvivsa8Civ5nz++pyVVBMjOMlgIUJw==
dependencies:
fuzzy "^0.1.1"
xtend "^4.0.0"
Expand Down

0 comments on commit 72a3f02

Please sign in to comment.