diff --git a/src/leaflet-sidepanel.ts b/src/leaflet-sidepanel.ts index e29420e..50da60b 100644 --- a/src/leaflet-sidepanel.ts +++ b/src/leaflet-sidepanel.ts @@ -68,9 +68,7 @@ class SidePanel extends L.Control { if (!!this.options.pushControls) { const map = this._map; - if (!!map) { - const mapContainer = - map instanceof HTMLElement ? map : map.getContainer(); + const mapContainer = map instanceof L.Map ? map.getContainer() : map; const controlsContainer = mapContainer.querySelector( '.leaflet-control-container' ) as HTMLElement; @@ -83,7 +81,6 @@ class SidePanel extends L.Control { `--panel-width-${this.options.panelPosition}`, this.options.size! ); // `!` 'cause we have a default value - } } if (this.options.hasTabs) { diff --git a/tests/leaflet.sidepanel.test.ts b/tests/leaflet.sidepanel.test.ts index 5df947c..d432963 100644 --- a/tests/leaflet.sidepanel.test.ts +++ b/tests/leaflet.sidepanel.test.ts @@ -157,12 +157,9 @@ describe('SidePanel', () => { ) as HTMLElement; expect( controlsContainer.classList.contains('leaflet-animate-control-container') - ).toBe(false); + ).toBe(true); sidePanel.toggle(); - expect( - controlsContainer.classList.contains('leaflet-animate-control-container') - ).toBe(true); expect( controlsContainer.classList.contains(options.panelPosition + '-opened') ).toBe(true); @@ -204,10 +201,16 @@ describe('SidePanel', () => { const controlsContainer = document.querySelector( '.leaflet-control-container' ) as HTMLElement; - sidePanel.toggle(); expect( controlsContainer.classList.contains('leaflet-animate-control-container') ).toBe(false); + expect( + controlsContainer.classList.toString().match(/-opened|-closed/g) + ).toBeNull(); + sidePanel.toggle(); + expect( + controlsContainer.classList.toString().match(/-opened|-closed/g) + ).toBeNull(); }); it('should warn if position option is set', () => { @@ -604,8 +607,6 @@ describe('SidePanel with HTMLElement', () => { // leaflet expects a map instance but also accepts HTMLElement .addTo(map); - sidePanel.toggle(); // This will trigger the `pushControls` logic - const controlsContainer = (map as unknown as HTMLElement).querySelector( '.leaflet-control-container' ) as HTMLElement;