Skip to content

Commit

Permalink
Fix tests and update collapse() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Falke-Design authored and jonkoops committed Jul 14, 2023
1 parent 9ec44b4 commit 0232c56
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions spec/suites/SpecHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ chai.util.addMethod(chai.Assertion.prototype, 'nearLatLng', function (expected,

// A couple of tests need the browser to be touch-capable
it.skipIfNotTouch = Browser.touch ? it : it.skip;
it.skipIfTouch = Browser.touchNative ? it.skip : it;

export const touchEventType = Browser.touchNative ? 'touch' : 'pointer';
// Note: this override is needed to workaround prosthetic-hand fail,
Expand Down
2 changes: 1 addition & 1 deletion spec/suites/control/Control.LayersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('Control.Layers', () => {
expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.be.ok;
});

it('collapses when mouse is out', () => {
it.skipIfTouch('collapses when mouse is out', () => {
const layersCtrl = new Control.Layers(null, null, {collapsed: true}).addTo(map);
UIEventSimulator.fire('pointerenter', layersCtrl._container, {pointerType});
expect(map._container.querySelector('.leaflet-control-layers-expanded')).not.to.be.null;
Expand Down
10 changes: 6 additions & 4 deletions src/control/Control.Layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ export const Layers = Control.extend({

// @method collapse(): this
// Collapse the control container if expanded.
collapse(e) {
if (e.type === 'pointerleave' && e.pointerType !== 'mouse') {
return;
collapse(ev) {
// On touch devices `pointerleave` is fired while clicking on a checkbox.
// The control was collapsed instead of adding the layer to the map. So we collapse only if it is a mouse.
// Or it is called directly by the user
if (!ev || (ev.type === 'pointerleave' && ev.pointerType === 'mouse')) {
this._container.classList.remove('leaflet-control-layers-expanded');
}
this._container.classList.remove('leaflet-control-layers-expanded');
return this;
},

Expand Down

0 comments on commit 0232c56

Please sign in to comment.