From da82a542b51cbf75e018c8b4e5a7a35fc54681b1 Mon Sep 17 00:00:00 2001 From: matthew44-mappable <155086725+matthew44-mappable@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:49:53 +0300 Subject: [PATCH] Fix text overflow and submit on enter (#40) Fixes # --- src/common/utils.ts | 7 +++++++ .../MMapWaypointInput/index.css | 3 ++- .../MMapWaypointInput/index.ts | 16 +++++++++----- src/controls/MMapRouteControl/index.ts | 21 +++++++++++++++---- .../MMapSearchControl/MMapSuggest/index.ts | 1 + 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/common/utils.ts b/src/common/utils.ts index aecdec5..e51acdd 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -1,3 +1,5 @@ +import type {LngLat} from '@mappable-world/mappable-types'; + export function createMMapElement(className?: string): HTMLElement { const el = document.createElement('mappable'); if (className) { @@ -5,3 +7,8 @@ export function createMMapElement(className?: string): HTMLElement { } return el; } + +export function areFuzzyEqual(a: LngLat, b: LngLat, tolerance = 1e-6): boolean { + const d = [a[0] - b[0], a[1] - b[1]]; + return -tolerance < d[0] && d[0] < tolerance && -tolerance < d[1] && d[1] < tolerance; +} diff --git a/src/controls/MMapRouteControl/MMapWaypointInput/index.css b/src/controls/MMapRouteControl/MMapWaypointInput/index.css index b642836..37e1927 100644 --- a/src/controls/MMapRouteControl/MMapWaypointInput/index.css +++ b/src/controls/MMapRouteControl/MMapWaypointInput/index.css @@ -36,7 +36,8 @@ .mappable--route-control_waypoint-input__field { box-sizing: border-box; height: 40px; - padding: 12px; + padding: 12px 30px 12px 12px; + text-overflow: ellipsis; border: none; border-radius: 8px; background: rgba(92, 94, 102, 0.06); diff --git a/src/controls/MMapRouteControl/MMapWaypointInput/index.ts b/src/controls/MMapRouteControl/MMapWaypointInput/index.ts index 1da60a2..bde3bf5 100644 --- a/src/controls/MMapRouteControl/MMapWaypointInput/index.ts +++ b/src/controls/MMapRouteControl/MMapWaypointInput/index.ts @@ -32,6 +32,7 @@ export type SelectWaypointArgs = { export type MMapWaypointInputProps = { type: 'from' | 'to'; inputPlaceholder: string; + value?: string; waypoint?: LngLat | null; geolocationTextInput?: string; search?: ({params, map}: CustomSearch) => Promise | SearchResponse; @@ -68,6 +69,10 @@ export class MMapWaypointInput extends mappable.MMapComplexEntity { this._inputEl.value = text; }, - onSuggestClick: (params: SearchParams) => { - this._inputEl.value = params.text; + onSuggestClick: () => { this._submitWaypointInput(); } }); @@ -167,7 +171,7 @@ export class MMapWaypointInput extends mappable.MMapComplexEntity { this._isInputFocused = true; + this._suggestComponent.update({suggestNavigationAction: undefined}); this._addDirectChild(this._suggestComponent); this._updateIndicatorStatus('focus'); }; @@ -239,6 +244,7 @@ export class MMapWaypointInput extends mappable.MMapComplexEntity; @@ -204,8 +205,12 @@ class MMapCommonRouteControl extends mappable.MMapComplexEntity { const [fromOld, toOld] = this._waypoints; - this._waypointInputToElement.update({waypoint: fromOld === null ? null : fromOld.geometry.coordinates}); - this._waypointInputFromElement.update({waypoint: toOld === null ? null : toOld.geometry.coordinates}); + const fromValue = this._waypointInputFromElement.getValue(); + const toValue = this._waypointInputToElement.getValue(); + this._waypointInputToElement.update({ + waypoint: fromOld === null ? null : fromOld.geometry.coordinates, + value: !fromValue ? null : fromValue + }); + this._waypointInputFromElement.update({ + waypoint: toOld === null ? null : toOld.geometry.coordinates, + value: !toValue ? null : toValue + }); }; private _onUpdateWaypoints(feature: Feature | null, index: number) { diff --git a/src/controls/MMapSearchControl/MMapSuggest/index.ts b/src/controls/MMapSearchControl/MMapSuggest/index.ts index 61b10a7..a53bd26 100644 --- a/src/controls/MMapSearchControl/MMapSuggest/index.ts +++ b/src/controls/MMapSearchControl/MMapSuggest/index.ts @@ -54,6 +54,7 @@ class MMapSuggest extends mappable.MMapComplexEntity { this._addSuggestItems(suggestResult, this._props.onSuggestClick); + this._getSuggestElements().at(0)?.classList.add(ACTIVE_CLASS); this._rootElement?.classList.toggle(HIDE_CLASS, !this.children.length); };