add keyboard accessibility to markers, close #1355
This commit is contained in:
parent
9f50ab8dbb
commit
40179ed11f
@ -11,6 +11,7 @@ L.Marker = L.Class.extend({
|
||||
title: '',
|
||||
clickable: true,
|
||||
draggable: false,
|
||||
keyboard: true,
|
||||
zIndexOffset: 0,
|
||||
opacity: 1,
|
||||
riseOnHover: false,
|
||||
@ -121,6 +122,10 @@ L.Marker = L.Class.extend({
|
||||
|
||||
L.DomUtil.addClass(icon, classToAdd);
|
||||
|
||||
if (options.keyboard) {
|
||||
icon.tabIndex = '0';
|
||||
}
|
||||
|
||||
this._icon = icon;
|
||||
|
||||
this._initInteraction();
|
||||
@ -213,6 +218,7 @@ L.Marker = L.Class.extend({
|
||||
|
||||
L.DomUtil.addClass(icon, 'leaflet-clickable');
|
||||
L.DomEvent.on(icon, 'click', this._onMouseClick, this);
|
||||
L.DomEvent.on(icon, 'keypress', this._onKeyPress, this);
|
||||
|
||||
for (var i = 0; i < events.length; i++) {
|
||||
L.DomEvent.on(icon, events[i], this._fireMouseEvent, this);
|
||||
@ -244,6 +250,15 @@ L.Marker = L.Class.extend({
|
||||
});
|
||||
},
|
||||
|
||||
_onKeyPress: function (e) {
|
||||
if (e.keyCode === 13) {
|
||||
this.fire('click', {
|
||||
originalEvent: e,
|
||||
latlng: this._latlng
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
_fireMouseEvent: function (e) {
|
||||
|
||||
this.fire(e.type, {
|
||||
|
Loading…
Reference in New Issue
Block a user