fix: clear previous alert timeout when opening a new alert

Otherwise, when an infinite alert replace an alert with a finite duration,
this first alert timeout will close the second alert.

Co-authored-by: David Larlet <david@larlet.fr>
This commit is contained in:
Yohan Boniface 2025-01-31 16:42:38 +01:00
parent 3e9982c8cb
commit bcd69ccb47

View file

@ -57,8 +57,11 @@ class uMapAlert extends uMapElement {
this.container.dataset.duration = duration
this.element.textContent = message
this.setAttribute('open', 'open')
if (this._timeoutId) {
clearTimeout(this._timeoutId)
}
if (Number.isFinite(duration)) {
setTimeout(() => {
this._timeoutId = setTimeout(() => {
this._hide()
}, duration)
}