Skip to content
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: Block focus removed even on clicking the inspector control to add Url #68627

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,20 +612,29 @@ export default function NavigationLinkEdit( {
// If there is no link then remove the auto-inserted block.
// This avoids empty blocks which can provided a poor UX.
if ( ! url ) {
// Fixes https://github.com/WordPress/gutenberg/issues/61361
// There's a chance we're closing due to the user selecting the browse all button.
// Only move focus if the focus is still within the popover ui. If it's not within
// the popover, it's because something has taken the focus from the popover, and
// we don't want to steal it back.
const inspectorControls =
document.querySelector(
'.editor-sidebar'
);

// Only move focus if the focus is still within the popover UI or Inspector Controls.
// If the focus is not within these elements, it means something else has taken the focus
// (e.g., outside the editor), and we can safely proceed to remove the block.
if (
linkUIref.current.contains(
window.document.activeElement
) ||
inspectorControls.contains(
window.document.activeElement
)
) {
// Select the previous block to keep focus nearby
selectPreviousBlock( clientId, true );
// Focus is within the popover or inspector; don't remove the block.
return;
}

// Select the previous block to keep focus nearby.
selectPreviousBlock( clientId, true );

// Remove the link.
onReplace( [] );
return;
Expand Down
Loading