Skip to content

Commit 274f866

Browse files
fix: fix search shortcut broken and make focus work each time (#2940)
2 parents 43b17a2 + 6d428de commit 274f866

File tree

7 files changed

+52
-60
lines changed

7 files changed

+52
-60
lines changed

umap/static/umap/css/form.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,6 @@ i.info {
549549
background-image: url('../img/16-white.svg');
550550
}
551551

552-
.with-transition {
553-
transition: all .7s;
554-
}
555-
556552
.umap-empty:before,
557553
.umap-to-polygon:before,
558554
.umap-clone:before,

umap/static/umap/js/modules/rendering/controls.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,13 @@ export const SearchControl = BaseButton.extend({
242242
const [container, { input, resultsContainer }] =
243243
Utils.loadTemplateWithRefs(template)
244244
const id = Math.random()
245+
this.search = new U.Search(
246+
this._umap._leafletMap,
247+
input,
248+
this.layer,
249+
this.photonOptions
250+
)
245251
this._umap.panel.open({ content: container }).then(() => {
246-
this.search = new U.Search(
247-
this._umap._leafletMap,
248-
input,
249-
this.layer,
250-
this.photonOptions
251-
)
252252
this.search.on('ajax:send', () => {
253253
this._umap.fire('dataloading', { id: id })
254254
})

umap/static/umap/js/modules/ui/panel.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export class Panel {
2626
}
2727

2828
open({ content, className, highlight, actions = [] } = {}) {
29+
let isOpen = false
2930
if (this.isOpen()) {
31+
isOpen = true
3032
this.onClose()
3133
}
32-
this.container.className = `with-transition panel window ${this.className} ${
33-
this.mode || ''
34-
}`
34+
this.container.className = `with-transition panel window ${this.className} ${this.mode || ''} ${isOpen ? 'on' : ''}`
3535
if (highlight) {
3636
this.container.dataset.highlight = highlight
3737
}
@@ -56,8 +56,22 @@ export class Panel {
5656
}
5757
if (className) DomUtil.addClass(body, className)
5858
const promise = new Promise((resolve, reject) => {
59-
DomUtil.addClass(this.container, 'on')
60-
resolve(this)
59+
if (isOpen) {
60+
resolve(this)
61+
} else {
62+
Promise.all(
63+
this.container.getAnimations().map((animation) => animation.finished)
64+
)
65+
.then(() => {
66+
resolve(this)
67+
})
68+
.catch(() => {
69+
// Panel has been removed, so the DOM has changed, so the animations
70+
// were cancelled, we want the new panel callabck to be called anyway.
71+
resolve(this)
72+
})
73+
this.container.classList.add('on')
74+
}
6175
})
6276
DomEvent.on(closeButton, 'click', this.close, this)
6377
DomEvent.on(resizeButton, 'click', this.resize, this)
@@ -83,8 +97,8 @@ export class Panel {
8397
}
8498

8599
onClose() {
86-
if (DomUtil.hasClass(this.container, 'on')) {
87-
DomUtil.removeClass(this.container, 'on')
100+
if (this.container.classList.contains('on')) {
101+
this.container.classList.remove('on')
88102
this._leafletMap.invalidateSize({ pan: false })
89103
}
90104
}

umap/static/umap/js/modules/umap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ export default class Umap {
481481
}
482482

483483
search() {
484-
if (this._leafletMap._controls.search) this._leafletMap._controls.search.open()
484+
if (this._leafletMap._controls.search) this._leafletMap._controls.search.onClick()
485485
}
486486

487487
hasEditMode() {

umap/static/umap/map.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ html[dir="rtl"] .leaflet-tooltip-pane>* {
2424
margin-inline-start: 5px;
2525
}
2626

27+
/* *********** */
28+
/* Generic */
29+
/* *********** */
30+
.with-transition {
31+
transition: all var(--transition);
32+
}
33+
2734
/* *********** */
2835
/* Map details */
2936
/* *********** */
@@ -1069,7 +1076,7 @@ ul.photon-autocomplete {
10691076
font-weight: bold;
10701077
}
10711078

1072-
.leaflet-overlay-pane > svg {
1079+
.leaflet-overlay-pane>svg {
10731080
z-index: var(--zindex-orphan-marker);
10741081
}
10751082

umap/static/umap/vars.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
--zindex-orphan-marker: 401;
6565

6666
--block-shadow: 0 1px 7px var(--color-mediumGray);
67+
--transition: 300ms;
6768
}
69+
6870
.dark {
6971
--background-color: var(--color-darkGray);
7072
--text-color: #efefef;

umap/tests/integration/test_import.py

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ def test_layers_list_is_updated(live_server, tilelayer, page):
2222
page.locator("[name=layer-id]").select_option(label="Import in a new layer")
2323
page.get_by_role("button", name="Manage layers").click()
2424
page.get_by_role("button", name="Add a layer").click()
25-
page.locator('input[name="name"]').click()
2625
page.locator('input[name="name"]').fill("foobar")
27-
page.wait_for_timeout(300) # Time for the input debounce.
26+
page.wait_for_timeout(300) # Wait for the input throttling.
2827
page.get_by_role("button", name=f"Import data ({modifier}+I)").click()
2928
# Should still work
3029
page.locator("[name=layer-id]").select_option(label="Import in a new layer")
@@ -108,9 +107,7 @@ def test_import_geojson_from_textarea(tilelayer, live_server, page):
108107
expect(markers).to_have_count(0)
109108
expect(paths).to_have_count(0)
110109
expect(layers).to_have_count(0)
111-
button = page.get_by_title("Import data")
112-
expect(button).to_be_visible()
113-
button.click()
110+
page.get_by_title("Import data").click()
114111
textarea = page.locator(".umap-import textarea")
115112
path = Path(__file__).parent.parent / "fixtures/test_upload_data.json"
116113
textarea.fill(path.read_text())
@@ -133,9 +130,7 @@ def test_import_invalid_data(tilelayer, live_server, page):
133130
expect(markers).to_have_count(0)
134131
expect(paths).to_have_count(0)
135132
expect(layers).to_have_count(0)
136-
button = page.get_by_title("Import data")
137-
expect(button).to_be_visible()
138-
button.click()
133+
page.get_by_title("Import data").click()
139134
textarea = page.locator(".umap-import textarea")
140135
textarea.fill("invalid data")
141136
for format in ["geojson", "csv", "gpx", "kml", "georss", "osm", "umap"]:
@@ -153,9 +148,7 @@ def test_import_kml_from_textarea(tilelayer, live_server, page):
153148
expect(markers).to_have_count(0)
154149
expect(paths).to_have_count(0)
155150
expect(layers).to_have_count(0)
156-
button = page.get_by_title("Import data")
157-
expect(button).to_be_visible()
158-
button.click()
151+
page.get_by_title("Import data").click()
159152
textarea = page.locator(".umap-import textarea")
160153
path = Path(__file__).parent.parent / "fixtures/test_upload_data.kml"
161154
textarea.fill(path.read_text())
@@ -177,9 +170,7 @@ def test_import_gpx_from_textarea(tilelayer, live_server, page, settings):
177170
expect(markers).to_have_count(0)
178171
expect(paths).to_have_count(0)
179172
expect(layers).to_have_count(0)
180-
button = page.get_by_title("Import data")
181-
expect(button).to_be_visible()
182-
button.click()
173+
page.get_by_title("Import data").click()
183174
textarea = page.locator(".umap-import textarea")
184175
path = Path(__file__).parent.parent / "fixtures/test_upload_data.gpx"
185176
textarea.fill(path.read_text())
@@ -234,9 +225,7 @@ def test_import_osm_from_textarea(tilelayer, live_server, page):
234225
markers = page.locator(".leaflet-marker-icon")
235226
expect(markers).to_have_count(0)
236227
expect(layers).to_have_count(0)
237-
button = page.get_by_title("Import data")
238-
expect(button).to_be_visible()
239-
button.click()
228+
page.get_by_title("Import data").click()
240229
textarea = page.locator(".umap-import textarea")
241230
path = Path(__file__).parent.parent / "fixtures/test_upload_data_osm.json"
242231
textarea.fill(path.read_text())
@@ -254,9 +243,7 @@ def test_import_csv_from_textarea(tilelayer, live_server, page):
254243
markers = page.locator(".leaflet-marker-icon")
255244
expect(markers).to_have_count(0)
256245
expect(layers).to_have_count(0)
257-
button = page.get_by_title("Import data")
258-
expect(button).to_be_visible()
259-
button.click()
246+
page.get_by_title("Import data").click()
260247
textarea = page.locator(".umap-import textarea")
261248
path = Path(__file__).parent.parent / "fixtures/test_upload_data.csv"
262249
textarea.fill(path.read_text())
@@ -422,9 +409,7 @@ def test_import_geometry_collection(live_server, page, tilelayer):
422409
expect(markers).to_have_count(0)
423410
expect(paths).to_have_count(0)
424411
expect(layers).to_have_count(0)
425-
button = page.get_by_title("Import data")
426-
expect(button).to_be_visible()
427-
button.click()
412+
page.get_by_title("Import data").click()
428413
textarea = page.locator(".umap-import textarea")
429414
textarea.fill(json.dumps(data))
430415
page.locator('select[name="format"]').select_option("geojson")
@@ -477,9 +462,7 @@ def test_import_geometry_collection_in_feature(live_server, page, tilelayer):
477462
expect(markers).to_have_count(0)
478463
expect(paths).to_have_count(0)
479464
expect(layers).to_have_count(0)
480-
button = page.get_by_title("Import data")
481-
expect(button).to_be_visible()
482-
button.click()
465+
page.get_by_title("Import data").click()
483466
textarea = page.locator(".umap-import textarea")
484467
textarea.fill(json.dumps(data))
485468
page.locator('select[name="format"]').select_option("geojson")
@@ -513,9 +496,7 @@ def test_import_multipolygon(live_server, page, tilelayer):
513496
paths = page.locator("path")
514497
expect(paths).to_have_count(0)
515498
expect(layers).to_have_count(0)
516-
button = page.get_by_title("Import data")
517-
expect(button).to_be_visible()
518-
button.click()
499+
page.get_by_title("Import data").click()
519500
textarea = page.locator(".umap-import textarea")
520501
textarea.fill(json.dumps(data))
521502
page.locator('select[name="format"]').select_option("geojson")
@@ -545,9 +526,7 @@ def test_import_multipolyline(live_server, page, tilelayer):
545526
paths = page.locator("path")
546527
expect(paths).to_have_count(0)
547528
expect(layers).to_have_count(0)
548-
button = page.get_by_title("Import data")
549-
expect(button).to_be_visible()
550-
button.click()
529+
page.get_by_title("Import data").click()
551530
textarea = page.locator(".umap-import textarea")
552531
textarea.fill(json.dumps(data))
553532
page.locator('select[name="format"]').select_option("geojson")
@@ -577,9 +556,7 @@ def test_import_false_multipoint(live_server, page, tilelayer):
577556
markers = page.locator(".leaflet-marker-icon")
578557
expect(markers).to_have_count(0)
579558
expect(layers).to_have_count(0)
580-
button = page.get_by_title("Import data")
581-
expect(button).to_be_visible()
582-
button.click()
559+
page.get_by_title("Import data").click()
583560
textarea = page.locator(".umap-import textarea")
584561
textarea.fill(json.dumps(data))
585562
page.locator('select[name="format"]').select_option("geojson")
@@ -1056,9 +1033,7 @@ def test_import_osm_relation(tilelayer, live_server, page):
10561033
paths = page.locator("path")
10571034
expect(paths).to_have_count(0)
10581035
expect(layers).to_have_count(0)
1059-
button = page.get_by_title("Import data")
1060-
expect(button).to_be_visible()
1061-
button.click()
1036+
page.get_by_title("Import data").click()
10621037
textarea = page.locator(".umap-import textarea")
10631038
file_path = Path(__file__).parent.parent / "fixtures/test_import_osm_relation.json"
10641039
textarea.fill(file_path.read_text())
@@ -1076,9 +1051,7 @@ def test_import_georss_from_textarea(tilelayer, live_server, page):
10761051
markers = page.locator(".leaflet-marker-icon")
10771052
expect(markers).to_have_count(0)
10781053
expect(layers).to_have_count(0)
1079-
button = page.get_by_title("Import data")
1080-
expect(button).to_be_visible()
1081-
button.click()
1054+
page.get_by_title("Import data").click()
10821055
textarea = page.locator(".umap-import textarea")
10831056
path = Path(__file__).parent.parent / "fixtures/test_upload_georss.xml"
10841057
textarea.fill(path.read_text())

0 commit comments

Comments
 (0)