Skip to content

Commit

Permalink
Fix #1 search on enter interferes with selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Sep 11, 2023
1 parent 636e165 commit 3d68d14
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Change Log

## v0.4.0
## v1.0.0

- Adds optional callback to options so that developers can take additional action when the user selects a result.
- Fixes a bug with search-on-enter interfering with arrow key-based navigation (https://github.com/stadiamaps/maplibre-search-box/issues/1)

## v0.6.0

- Support changing the base URL (ex: for EU endpoints)

## v0.5.0

- Adds arrow key-based navigation!

## v0.6.0
## v0.4.0

- Support changing the base URL (ex: for EU endpoints)
- Adds optional callback to options so that developers can take additional action when the user selects a result.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

var control = new MapLibreSearchControl({
useMapFocusPoint: true,
searchOnEnter: true,
});
var navControl = new maplibregl.NavigationControl();
var map = new maplibregl.Map({
container: "map",
style: "https://tiles.stadiamaps.com/styles/alidade_smooth.json", // stylesheet location
style: "https://tiles.stadiamaps.com/styles/outdoors.json", // stylesheet location
center: [-74.5, 40], // starting position [lng, lat]
zoom: 2, // starting zoom
hash: "map",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stadiamaps/maplibre-search-box",
"version": "0.6.0",
"version": "1.0.0",
"homepage": "https://docs.stadiamaps.com/",
"repository": "https://github.com/stadiamaps/maplibre-search-box",
"license": "BSD-3-Clause",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ export class MapLibreSearchControl implements IControl {
async onKey(e: KeyboardEvent) {
switch (e.key) {
case "Enter":
if (this.options.searchOnEnter) {
await this.onInput(e, true);
} else if (this.selectedResultIndex !== null) {
if (this.selectedResultIndex !== null) {
this.onSelected(this.resultFeatures[this.selectedResultIndex]);
this.input.blur();
} else if (this.options.searchOnEnter) {
await this.onInput(e, true);
}
break;
case "Escape":
Expand Down

0 comments on commit 3d68d14

Please sign in to comment.