Skip to content

Commit

Permalink
Fix close events being fired for popups that aren't open (#3901)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzetter committed Mar 26, 2024
1 parent c91d7fb commit 816f898
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### 🐞 Bug fixes
- Fix type definition on `localIdeographFontFamily` ([#3896](https://github.com/maplibre/maplibre-gl-js/pull/3896))
- Fix unwanted panning changes at the end of a panning motion ([#3872](https://github.com/maplibre/maplibre-gl-js/issues/3872))
- Fix `close` events being fired for popups that aren't open
- _...Add new stuff here..._

## 4.1.1
Expand Down
12 changes: 12 additions & 0 deletions src/ui/popup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ describe('popup', () => {
expect(onClose).toHaveBeenCalled();
});

test('Popup does not fire close event when removed if it is not on the map', () => {
const onClose = jest.fn();

new Popup()
.setText('Test')
.setLngLat([0, 0])
.on('close', onClose)
.remove();

expect(onClose).not.toHaveBeenCalled();
});

test('Popup fires open event when added', () => {
const map = createMap();
const onOpen = jest.fn();
Expand Down
3 changes: 1 addition & 2 deletions src/ui/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,9 @@ export class Popup extends Evented {
this._map.off('drag', this._onDrag);
this._map._canvasContainer.classList.remove('maplibregl-track-pointer');
delete this._map;
this.fire(new Event('close'));
}

this.fire(new Event('close'));

return this;
};

Expand Down

0 comments on commit 816f898

Please sign in to comment.