You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DataViews: async loading controls foil first focus on mount #75540
I’ve noticed this in the quick edit panel of the site editor where the first time the “Author” field dropdown opens the close button is focused instead of the select element as happens on any subsequent opening of the dropdown.
More context
It looks like async loading controls were introduced with #72254 then #72322 brought about the possibility for these controls to be focused when their containing popovers or dialogs mount.
Step-by-step reproduction instructions
Enable the “Data Views: add Quick Edit” experiment from the Gutenberg Experiments settings page
Visit the Site editor
View Pages (in table or grid layout)
Open the quick edit dialog
Click the “Author” field
Observe the focus is on the dropdown’s close button
Screenshots, screen recording, code snippet
foiled-first-focus-on-mount.mp4
Environment info
WP 6.9 / Gutenberg trunk
Firefox / Chrome
macOS
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Please confirm which theme type you used for testing.
@stokesman As per my research, it looks like this is happening due to the async operation. When the click event is triggered, the authors are fetched through an API call. At that moment, the control is not yet fully initialised, so the focus falls back from firstInputElement to firstElement. As a result, the first time the dialog opens, the focus goes to the close button.
the control is not yet fully initialised, so the focus falls back from firstInputElement to firstElement. As a result, the first time the dialog opens, the focus goes to the close button.
We could manually trigger a refocus once the fetching completes or maybe a loading state?
so the focus falls back from firstInputElement to firstElement
Yes and thanks to that this issue can probably be considered a potential enhancement instead of a bug. I'd been thinking this since I made the issue and now I’ll change it.
We could manually trigger a refocus once the fetching completes or maybe a loading state?
I assume all the async controls do have a loading state – as the select control shown in the screen recording has:
I’d doubt that focus should be moved to the control if loading takes longer than ~200 milliseconds. With that in mind, my current thought is to make the useFocusOnMount hook have an option that makes it retry until a maximum timeout has elapsed before doing the fallback. Whatever the solution, it seems low priority.
Activity
nirav7707 commentedon Feb 17, 2026
@stokesman As per my research, it looks like this is happening due to the async operation. When the click event is triggered, the authors are fetched through an API call. At that moment, the control is not yet fully initialised, so the focus falls back from firstInputElement to firstElement. As a result, the first time the dialog opens, the focus goes to the close button.
Mayank-Tripathi32 commentedon Feb 18, 2026
We could manually trigger a refocus once the fetching completes or maybe a loading state?
stokesman commentedon Feb 18, 2026
Yes and thanks to that this issue can probably be considered a potential enhancement instead of a bug. I'd been thinking this since I made the issue and now I’ll change it.
I assume all the async controls do have a loading state – as the select control shown in the screen recording has:
gutenberg/packages/dataviews/src/components/dataform-controls/select.tsx
Lines 41 to 43 in c4e4fac
I’d doubt that focus should be moved to the control if loading takes longer than ~200 milliseconds. With that in mind, my current thought is to make the
useFocusOnMounthook have an option that makes it retry until a maximum timeout has elapsed before doing the fallback. Whatever the solution, it seems low priority.