From 4bf0f8379b0e91c20ed99bf3049e3f179c5572f4 Mon Sep 17 00:00:00 2001 From: Matthew Kalinin Date: Wed, 20 Nov 2024 15:05:34 +0300 Subject: [PATCH 1/2] Fix text overflow and submit on enter --- .../MMapRouteControl/MMapWaypointInput/index.css | 3 ++- .../MMapRouteControl/MMapWaypointInput/index.ts | 16 +++++++++++----- src/controls/MMapRouteControl/index.ts | 12 ++++++++++-- .../MMapSearchControl/MMapSuggest/index.ts | 1 + 4 files changed, 24 insertions(+), 8 deletions(-) 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 { 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); }; From 46ba3435b3cdd578d1ea8ac73c6798770e82d177 Mon Sep 17 00:00:00 2001 From: Matthew Kalinin Date: Wed, 20 Nov 2024 16:42:33 +0300 Subject: [PATCH 2/2] fix reset value --- src/common/utils.ts | 7 +++++++ src/controls/MMapRouteControl/index.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 2 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/index.ts b/src/controls/MMapRouteControl/index.ts index 274d295..760bb86 100644 --- a/src/controls/MMapRouteControl/index.ts +++ b/src/controls/MMapRouteControl/index.ts @@ -24,6 +24,7 @@ import { } from './helpers'; import './index.css'; import {formatDistance, formatDuration} from './utils'; +import {areFuzzyEqual} from '../../common/utils'; export type WaypointsArray = Array; @@ -204,8 +205,12 @@ class MMapCommonRouteControl extends mappable.MMapComplexEntity