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

allow keyboard events on shadow root hosts #1235

Merged

Conversation

mattclough1
Copy link
Contributor

What:
Resolves #1153

Why:
The current code only allows keyboard entry on elements with a ShadowRoot if the ShadowRoot has a focusable element

How:
The getActiveElement function previously checked for the existence of a shadowRoot on the currently active element, since active elements in a shadow DOM make the host element the active element in the light DOM, but this logic ignored the fact that host elements can also be active elements on their own.

Checklist:

  • [N/A] Documentation
  • Tests
  • Ready to be merged

Copy link

codesandbox-ci bot commented Sep 24, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 3f3a23a:

Sandbox Source
priceless-thompson-vd5dxf Issue #1153

Copy link
Member

@ph-fritsche ph-fritsche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing to this library. 💙

tests/keyboard/index.ts Outdated Show resolved Hide resolved
tests/keyboard/index.ts Outdated Show resolved Hide resolved
src/utils/focus/getActiveElement.ts Outdated Show resolved Hide resolved
@ph-fritsche ph-fritsche merged commit 0437f2e into testing-library:main Feb 4, 2025
3 checks passed
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

Successfully merging this pull request may close these issues.

User Events: keyboard does not target focused element with shadow dom
2 participants