Skip to content

Commit

Permalink
InfoWindow close button Prevent event bubbling (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
deyihu authored Jul 3, 2024
1 parent 7a3aaf3 commit 670c0f6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/ui/InfoWindow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isFunction, isNumber, isObject, isString } from '../core/util';
import { createEl, addDomEvent, removeDomEvent } from '../core/util/dom';
import { createEl, addDomEvent, removeDomEvent, stopPropagation, preventDefault } from '../core/util/dom';
import Coordinate from '../geo/Coordinate';
import Point from '../geo/Point';
import Size from '../geo/Size';
Expand Down Expand Up @@ -49,7 +49,7 @@ const EMPTY_SIZE = new Size(0, 0);
class InfoWindow extends UIComponent {

options: InfoWindowOptionsType;
_onCloseBtnClick: () => void;
_onCloseBtnClick: (event: MouseEvent | TouchEvent) => void;

// TODO: obtain class in super
_getClassName() {
Expand Down Expand Up @@ -198,7 +198,13 @@ class InfoWindow extends UIComponent {
} else {
msgContent.appendChild(this.options['content'] as HTMLElement);
}
this._onCloseBtnClick = this.hide.bind(this);
this._onCloseBtnClick = (event) => {
if (!this.options.eventsPropagation) {
preventDefault(event);
stopPropagation(event);
}
this.hide();
}
const closeBtn = dom.querySelector('.maptalks-close');
addDomEvent(closeBtn as HTMLElement, 'click touchend', this._onCloseBtnClick);
//reslove content
Expand Down

0 comments on commit 670c0f6

Please sign in to comment.