Skip to content

DataViews: async loading controls foil first focus on mount #75540

Open

Description

@stokesman

Description

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

  1. Enable the “Data Views: add Quick Edit” experiment from the Gutenberg Experiments settings page
  2. Visit the Site editor
  3. View Pages (in table or grid layout)
  4. Open the quick edit dialog
  5. Click the “Author” field
  6. 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.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. nirav7707 commented on Feb 17, 2026

    @nirav7707
    Contributor

    @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.

  2. Mayank-Tripathi32 commented on Feb 18, 2026

    @Mayank-Tripathi32
    Member

    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?

  3. stokesman commented on Feb 18, 2026

    @stokesman
    ContributorAuthor

    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:

    if ( isLoading ) {
    return <Spinner />;
    }

    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.

  4. added
    [Priority] LowUsed to indicate that the issue at hand isn't a top priority to address and can be handled later
    and removed
    [Type] BugAn existing feature does not function as intended
    on Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Package] DataViews/packages/dataviews[Priority] LowUsed to indicate that the issue at hand isn't a top priority to address and can be handled later[Status] In ProgressTracking issues with work in progress[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions