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

Pan / Zoom is blocking <input> in foreignObject #99

Open
benoitlahoz opened this issue Feb 3, 2024 · 2 comments
Open

Pan / Zoom is blocking <input> in foreignObject #99

benoitlahoz opened this issue Feb 3, 2024 · 2 comments

Comments

@benoitlahoz
Copy link

Hello and thank you for this work!

I have an issue on inserting an HTML <input type="text" /> in a foreignObject: the HTML input doesn't take focus.
I guess the plugin listeners are having precedence over the input's one...

Any advice to resolve this?
Thank you.

@Fuzzyma
Copy link
Member

Fuzzyma commented Feb 3, 2024

Mh, that's a tough one. Ofc the default behavior needs to be prevented so that the browser is not scrolling or zooming.
I don't see a simple solution to that problem right now. You could try and listen to touchstart and touchend on the input yourself and focus it yourself maybe?

@benoitlahoz
Copy link
Author

Thank you.
It works!

// Get the foreignElement's input (here the input is wrapped in a <div>)
const input: HTMLInputElement = foreignElement.node.getElementsByTagName('input')[0];

// The listener for 'click outside'
const onClickOutside = (event: MouseEvent) => {
  if (event.target === input) {
     return false;
  }

  // Blur the inner input element.
  input.blur();

  // Remove the listener on window
  window.removeEventListener('mousedown', onClickOutside);
};

// Add listener to mousedown event
input.addEventListener('mousedown', () => {
  input.focus();

  // Add listener to 'click outside' event
  window.addEventListener('mousedown', onClickOutside);
});

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