Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listenning to event "keydown" #11

Closed
Spir opened this issue Jun 15, 2022 · 3 comments
Closed

Listenning to event "keydown" #11

Spir opened this issue Jun 15, 2022 · 3 comments

Comments

@Spir
Copy link

Spir commented Jun 15, 2022

Why is it not possible to listen to event "onkeydown" when using this library?

// this is never called

document.getElementById('svg-wrapper').addEventListener("keydown", function(event) {
  console.debug(event.keyCode);
});

If I remove the data attribute it works again:

<div id="svg-wrapper" tabindex="1" data-pan-on-drag data-zoom-on-wheel="min-scale: 0.3; max-scale: 1000;">
 <svg>...</svg>
</div>
@luncheon
Copy link
Owner

This is because clicking on the element does not give it focus.
Caused by calling preventDefault() on the pointerdown event.

@luncheon
Copy link
Owner

Sorry for the hassle, but how about this solution?

document
  .getElementById('svg-wrapper')
  .addEventListener("keydown", function(event) {
    console.debug(event.keyCode);
  });

// focus on click
document
  .getElementById('svg-wrapper')
  .addEventListener("pointerdown", function(event) {
    event.currentTarget.focus();
  });

https://codepen.io/luncheon/pen/rNJProp

@Spir
Copy link
Author

Spir commented Jun 15, 2022

This work perfectly thanks for your time!

@Spir Spir closed this as completed Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants