Skip to content

Commit f21c81b

Browse files
fix: focus on search input after opening it, even when already open
fix #2395 Co-authored-by: David Larlet <david@larlet.fr>
1 parent 02740d2 commit f21c81b

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

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: 17 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,18 @@ 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+
this.container.addEventListener(
63+
'transitionend',
64+
() => {
65+
resolve(this)
66+
},
67+
{ once: true }
68+
)
69+
this.container.classList.add('on')
70+
}
6171
})
6272
DomEvent.on(closeButton, 'click', this.close, this)
6373
DomEvent.on(resizeButton, 'click', this.resize, this)
@@ -83,8 +93,8 @@ export class Panel {
8393
}
8494

8595
onClose() {
86-
if (DomUtil.hasClass(this.container, 'on')) {
87-
DomUtil.removeClass(this.container, 'on')
96+
if (this.container.classList.contains('on')) {
97+
this.container.classList.remove('on')
8898
this._leafletMap.invalidateSize({ pan: false })
8999
}
90100
}

0 commit comments

Comments
 (0)