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

feat: dispatch FocusEvent in hidden documents #1252

Merged
merged 3 commits into from
Jan 15, 2025
Merged

feat: dispatch FocusEvent in hidden documents #1252

merged 3 commits into from
Jan 15, 2025

Conversation

ph-fritsche
Copy link
Member

@ph-fritsche ph-fritsche commented Jan 15, 2025

What:

Dispatch focus, focusin, blur and focusout events when document.visibilityState is hidden.

Why:

Browsers don't dispatch focus events on hidden windows.
Our simulation of the UI layer relies on these events and userEvent should act like a user does on a visible window.

How:

Patch HTMLElement.focus() and HTMLElement.blur() and dispatch the events if the document is hidden.

Checklist:

  • Tests
  • Ready to be merged

Copy link

codesandbox-ci bot commented Jan 15, 2025

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.

@ph-fritsche ph-fritsche marked this pull request as ready for review January 15, 2025 15:56
@ph-fritsche ph-fritsche linked an issue Jan 15, 2025 that may be closed by this pull request
@ph-fritsche ph-fritsche merged commit 1ed8b15 into main Jan 15, 2025
3 checks passed
@ph-fritsche ph-fritsche deleted the fix-focus branch January 15, 2025 19:34
Copy link

🎉 This PR is included in version 14.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@donaldpipowitch
Copy link

donaldpipowitch commented Feb 11, 2025

It looks like this change broke some integrations. See #1258. For me it broke react-aria here:

https://github.com/adobe/react-spectrum/blob/4b8b33a022a17c7df2d6ee6d23b6208b503973fe/packages/%40react-aria/interactions/src/useFocusVisible.ts#L138

TypeError: Cannot set property focus of [object HTMLElement] which has only a getter

I have to stick with 14.5.2 for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.focus() does not fire focus events if window is not focussed
2 participants