Patterns: fix focus loss when closing the Create pattern dialog from the block toolbar#78957
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@Mustafabharmal Looks like this is where that line was added - Block context menu: context menu not closing for disconnecting unsynced pattern menu items. We may need to check removing it again doesn't cause the other bug to come back. |
t-hamano
left a comment
There was a problem hiding this comment.
This PR only addresses the issue where the Create Pattern modal is cancelled. I have confirmed that it does not affect the behavior when detaching is performed.
What?
Fixes a focus management regression in the "Create pattern" dialog opened from the block toolbar Options menu.
Closes #78952.
Why?
When pressing Escape (or otherwise dismissing the dialog without saving), focus was lost because the
onClosehandler forCreatePatternModalcalledcloseBlockSettingsMenu(), which closed the entire parent dropdown menu. This left no visible focused element in the page.Other dialogs in the same Options menu — Lock, Rename, and Hide — all follow the correct pattern: they only close the modal on dismiss, keeping the dropdown open so focus can return to the triggering menu item.
How?
Removed
closeBlockSettingsMenu()from theonClosehandler inPatternConvertButton.closeBlockSettingsMenu()is still called correctly inhandleSuccess()after the user successfully creates a pattern, ensuring the dropdown closes after a committed action.onClose={ () => { setIsModalOpen( false ); - closeBlockSettingsMenu(); } }Testing Instructions
Screenshots or screencast
Before:
Testing.Create.Pattern.focus.loss.Before.Fix.mov
After:
Testing.Create.Pattern.focus.loss.After.Fix.mov