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

Modal does not restore focus inside custom element #120

Open
angrycat9000 opened this issue Feb 24, 2025 · 0 comments · May be fixed by #121
Open

Modal does not restore focus inside custom element #120

angrycat9000 opened this issue Feb 24, 2025 · 0 comments · May be fixed by #121

Comments

@angrycat9000
Copy link

Describe the bug

Modal does not return focus to the previous element on closing when hosted inside of a custom element shadow root.

To Reproduce

Steps to reproduce the behavior:

  1. Create a custom element with a shadow root that hosts a react render root
  2. Render a Modal and a button to open in the custom element shadowroot.
  3. Tab to the button and press enter to open the modal.
  4. Press Escape to close the modal
    • Expect: the original button to have focus
    • Result: the button is not focused

Reproducible Example

Minimal example by using CodeSandbox.

Expected behavior

The original button should have focus.

Screenshots

modal-focus-bug-edit.mp4

Environment (please complete the following information)

  • Operating System: windows
  • Browser, Version Chrome 133
  • react-overlays Version ?

Additional context

document.activeElement returns the custom element since it is the deepest element in the light DOM that has focus. However restoring focus to the custom element in the light DOM isn't enough. There could be multiple elements in the shadow DOM of the custom element. And at this point the shadowRoot.activeElement has lost the reference to the originally focused elements.

the activeElement would need to capture the deepest element piercing the shadow roots when saving the originally focused element.

@angrycat9000 angrycat9000 linked a pull request Feb 26, 2025 that will close this issue
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 a pull request may close this issue.

1 participant