-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix focus loss when creating pages from link control search results #40342
Conversation
Size Change: -2 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
@youknowriad, the LinkControl component closes after the page is created and focus is lost in my tests. ScreencastCleanShot.2022-04-14.at.21.18.26.mp4 |
Thanks for testing @Mamaduka I might have done something wrong when extracting the changes. I'll check this again tomorrow. |
Ok, so this is actually working as intended, but I still think this is a worthwhile change. Let me explain, so on the React 18 PR, without this change, the "link control" closes as soon as you "start" creating the page and not when it "finishes" creating the page. I think that's an issue because you don't see the feedback ... Also, the closing happens because for a small period of time (when the page is "creating") the focus is lost. The focus loss happens in trunk too but it's hard to see it because creating the page is generally fast and when the creation is finished, the focus is moved to the paragraph. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for providing more details, @youknowriad.
I can confirm that this fixed the issue by throttling the network and tracking the focus element.
This was cherry-picked to |
Extracted from #32765
What?
For some reason, in the React 18 upgrade PR #32765,
useFocusOutside
works better than trunk (I don't know why yet). Which means there were some failing e2e tests that actually show real bugs we have on trunk, more precisely "focus loss" bugs.One of them is in the inserter when creating pages from link control. This PR solves the focus loss there.
Why?
Focus loss is an a11y issue even if the inserter is kept open right now.
How?
We already have a dedicated logic in the component to avoid focus loss when switching from "editing link" to "showing link" but there's a third state "loading state while creating a page" that was not covered by the focus loss preventing logic. This PR just triggers the effect when the
isCreatingPage
boolean becomes true.Testing Instructions
1- Write a paragraph
2- Click the "add link" button
3- Write something in the input
4- Select "Create page" from the dropdown
5- The LinkControl component should still have focus and be visible.
(We already have an e2e test that covers this but it's passing in trunk because of the mystery bug in useFocusOutside, it will start failing in the React 18 upgrade if we do nothing :) )