Keyboard handler does not propagate escape key events #5234

Open
bertspaan opened this Issue Jan 6, 2017 · 2 comments

Projects

None yet

3 participants

@bertspaan
bertspaan commented Jan 6, 2017 edited

When using Leaflet with keyboard navigation enabled, the propagation of escape keydown events is stopped by L.Map.Keyboard:

_onKeyDown: function (e) {
  var key = e.keyCode;
  if (...) {
    // ...
  } else if (key === 27) { // 27 is escape key's keyCode
    map.closePopup();
  } else {
    return;
  }
  L.DomEvent.stop(e);
}

I need to capture escape key events in my application, but creating a Leaflet keypress handler with map.on — or using map._container.addEventListener directly — does not work.

Is this intentional? Why was the check for map._popup removed in 1eae171?

@perliedman
Member

Looking at the history for #3000, which 1eae171 is part of, it's probably just a refactor: the conditional isn't needed since it's ok to call closePopup even if there isn't already a popup open. Unfortunately, it also causes the issue you're seeing, since the escape key event will always be stopped and never propagate.

@snkashis do you have an opinion here? I guess reintroducing the check for an open popup would be good after all?

@snkashis
Member

Yes, reintroducing check sounds fine to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment