Don't turn enter keypress into clicks on map (#5507)
* Don't turn enter keypress into clicks on map But still preserve functionality to open marker's popup through enter keypress when focused. Fixes #5499. * Clean code Thanks @egoroof * Change name of keypress handler to _onKeyPress * Add unit test
This commit is contained in:
parent
d78dc21209
commit
b23d83f464
11
spec/suites/core/GeneralSpec.js
Normal file
11
spec/suites/core/GeneralSpec.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
describe('General', function () {
|
||||||
|
describe('noConflict', function () {
|
||||||
|
var leaflet = L;
|
||||||
|
|
||||||
|
after(function () {
|
||||||
|
L = leaflet;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(L.noConflict()).to.eql(leaflet);
|
||||||
|
});
|
||||||
|
});
|
@ -248,6 +248,18 @@ describe('Popup', function () {
|
|||||||
expect(map.hasLayer(layer._popup)).to.be(true);
|
expect(map.hasLayer(layer._popup)).to.be(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("can open a popup with enter keypress when marker has focus", function () {
|
||||||
|
var layer = new L.Marker([55.8, 37.6]).addTo(map);
|
||||||
|
layer.bindPopup("layer popup");
|
||||||
|
|
||||||
|
happen.keypress(layer._icon, {
|
||||||
|
keyCode: 13
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(map.hasLayer(layer._popup)).to.be(true);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("L.Map#openPopup", function () {
|
describe("L.Map#openPopup", function () {
|
||||||
|
@ -383,6 +383,7 @@ Layer.include({
|
|||||||
if (!this._popupHandlersAdded) {
|
if (!this._popupHandlersAdded) {
|
||||||
this.on({
|
this.on({
|
||||||
click: this._openPopup,
|
click: this._openPopup,
|
||||||
|
keypress: this._onKeyPress,
|
||||||
remove: this.closePopup,
|
remove: this.closePopup,
|
||||||
move: this._movePopup
|
move: this._movePopup
|
||||||
});
|
});
|
||||||
@ -398,6 +399,7 @@ Layer.include({
|
|||||||
if (this._popup) {
|
if (this._popup) {
|
||||||
this.off({
|
this.off({
|
||||||
click: this._openPopup,
|
click: this._openPopup,
|
||||||
|
keypress: this._onKeyPress,
|
||||||
remove: this.closePopup,
|
remove: this.closePopup,
|
||||||
move: this._movePopup
|
move: this._movePopup
|
||||||
});
|
});
|
||||||
@ -515,5 +517,11 @@ Layer.include({
|
|||||||
|
|
||||||
_movePopup: function (e) {
|
_movePopup: function (e) {
|
||||||
this._popup.setLatLng(e.latlng);
|
this._popup.setLatLng(e.latlng);
|
||||||
|
},
|
||||||
|
|
||||||
|
_onKeyPress: function (e) {
|
||||||
|
if (e.originalEvent.keyCode === 13) {
|
||||||
|
this._openPopup(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1307,9 +1307,9 @@ export var Map = Evented.extend({
|
|||||||
_handleDOMEvent: function (e) {
|
_handleDOMEvent: function (e) {
|
||||||
if (!this._loaded || DomEvent.skipped(e)) { return; }
|
if (!this._loaded || DomEvent.skipped(e)) { return; }
|
||||||
|
|
||||||
var type = e.type === 'keypress' && e.keyCode === 13 ? 'click' : e.type;
|
var type = e.type;
|
||||||
|
|
||||||
if (type === 'mousedown') {
|
if (type === 'mousedown' || type === 'keypress') {
|
||||||
// prevents outline when clicking on keyboard-focusable element
|
// prevents outline when clicking on keyboard-focusable element
|
||||||
DomUtil.preventOutline(e.target || e.srcElement);
|
DomUtil.preventOutline(e.target || e.srcElement);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user