Skip to content

Focus loss when closing the Create pattern dialog opened from the block toolbar #78952

Closed

Description

@afercia

Description

Some commands in the block toolbar 'Options' menu open a modal dialog.
When the modal dialog is open, the expectation is that pressing the Escape key will close the dialog and retur focus back to the item in the menu that opened it.

This works for all the 'Options" menu items except the 'Create pattern' one.

Screenshot ot the block toolbar 'Options' menu items to be tested:

Image

Step-by-step reproduction instructions

  • Create a post, add a Paragraph block.
  • From the block toolbar open the 'Options' menu.
  • Test the following items in the menu, you can either click on them or use the keyboard to move to them and press Enter.
    • Click 'Lock'. A modal dialog opens.
    • Press the Escape key. The dialog closes and focus is moved back to the trigger, as expected.
    • Click 'Rename'. A modal dialog opens.
    • Press the Escape key. The dialog closes and focus is moved back to the trigger, as expected.
    • Click 'Hide'. A modal dialog opens.
    • Press the Escape key. The dialog closes and focus is moved back to the trigger, as expected.
    • Click 'Create pattern'. A modal dialog opens.
    • Press the Escape key. The dialog closes. Observe the Options menu closes as well. Observe there is a focus loss.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress trunk 7.1-alpha-62161-src
  • Gutenberg 23.3.1 (trunk)

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. added
    [Type] Bug
    [Focus] Accessibility (a11y)
    on Jun 4, 2026
  2. afercia commented on Jun 4, 2026

    @afercia
    ContributorAuthor

    Video recording to illustrate the focus loss.
    Observe that after the menu closes unexpectedly, pressing the Tab key re-starts the tab order from the document root.

    Screen.Recording.2026-06-04.at.16.39.22.mov
  3. Mustafabharmal commented on Jun 4, 2026

    @Mustafabharmal
    Contributor

    Hi! I've identified the root cause of this focus loss issue. It's in packages/patterns/src/components/pattern-convert-button.js — the onClose callback for the CreatePatternModal incorrectly calls closeBlockSettingsMenu() when the modal is dismissed, which closes the entire Options dropdown and leaves focus stranded. Other dialogs in the same menu (Lock, Rename, Hide) only close the modal on dismiss, leaving the dropdown open for focus to return naturally. I'm working on a fix.

  4. added
    [Status] In Progress
    on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

[Focus] Accessibility (a11y)[Status] In Progress[Type] Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions