Feature: optionally allow popups to not close on pressing Esc (#5730)

* add test for disabled popup ESC key functionality

* add closeOnEscapeKey default option for popup

* add ESC key condition to prevent map.closePopup

* fix variable indentation

* revert unnecessary mapPopup variable back to map._popup

* add 4 spaces of indentation to variables
This commit is contained in:
Michael Fenwick 2017-08-28 08:11:54 -06:00 committed by Iván Sánchez Ortega
parent a5e03adb45
commit 0e36b948cd
3 changed files with 21 additions and 1 deletions

View File

@ -148,4 +148,19 @@ describe("Map.Keyboard", function () {
});
});
describe("popup closing disabled", function () {
it("close of popup when pressing escape disabled via options", function () {
var popup = L.popup({closeOnEscapeKey: false}).setLatLng([0, 0]).setContent('Null Island');
map.openPopup(popup);
expect(popup.isOpen()).to.be(true);
happen.keydown(document, {keyCode: 27});
happen.keyup(document, {keyCode: 27});
expect(popup.isOpen()).to.be(true);
});
});
});

View File

@ -87,6 +87,11 @@ export var Popup = DivOverlay.extend({
// the popup closing when another popup is opened.
autoClose: true,
// @option closeOnEscapeKey: Boolean = true
// Set it to `false` if you want to override the default behavior of
// the ESC key for closing of the popup.
closeOnEscapeKey: true,
// @option closeOnClick: Boolean = *
// Set it if you want to override the default behavior of the popup closing when user clicks
// on the map. Defaults to the map's [`closePopupOnClick`](#map-closepopuponclick) option.

View File

@ -162,7 +162,7 @@ export var Keyboard = Handler.extend({
} else if (key in this._zoomKeys) {
map.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);
} else if (key === 27 && map._popup) {
} else if (key === 27 && map._popup && map._popup.options.closeOnEscapeKey) {
map.closePopup();
} else {