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

EditContext intercepts input after focus is programmatically transferred #1458

Open
chuanqisun opened this issue Oct 26, 2024 · 2 comments
Open

Comments

@chuanqisun
Copy link

chuanqisun commented Oct 26, 2024

Describe the issue

Minimum repro: https://stackblitz.com/edit/vitejs-vite-y35czl?file=main.js

  <div id="editor-root"></div>
  <div>
    <button>transfer focus</button>
    <input id="input-element" />
  </div>
new EditorView({
  doc: `hello world `,
  extensions: [],
  parent: document.getElementById('editor-root'),
});

document.querySelector('button').onfocus = () =>
  document.querySelector('input').focus();

Repro recording

repro.mp4

Repro step

  1. Click inside the text editor to set focus
  2. Click "transfer focus" button
  3. Observe blinking cursor in text input
  4. Type anything

Expect: text input to receive all keyboard events
Actual: editor receives all keyboard events

  1. Set EditorView.EDIT_CONTEXT = false;
  2. Repeat steps, observe that issue goes away

Additional context

I need to move focus from one element to another as part of an accessibility focus trap implementation. In the real code, the element that transfers focus are dummy elements at the beginning and end of the focus trapped area.

Browser and platform

Chrome in Linux, Windows, and MacOS

Reproduction link

https://stackblitz.com/edit/vitejs-vite-y35czl?file=main.js

@marijnh
Copy link
Member

marijnh commented Oct 27, 2024

That appears to be another bug in Chrome's implementation of EditContext. I've reported it as issue 375711382. Until they fix it, the only advice I can offer is to set up your event handlers to avoid triggering this.

@chuanqisun
Copy link
Author

Thank you for distilling the repro and reporting to Chrome.

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