Skip to content

Commit

Permalink
Focus canvas from footer breadcrumb click
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj committed Jun 4, 2024
1 parent 8bd8957 commit 3901248
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/block-editor/src/components/block-breadcrumb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { chevronRightSmall, Icon } from '@wordpress/icons';
import BlockTitle from '../block-title';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';

/**
* Block breadcrumb component, displaying the hierarchy of the current block selection as a breadcrumb.
Expand All @@ -37,6 +38,10 @@ function BlockBreadcrumb( { rootLabelText } ) {
}, [] );
const rootLabel = rootLabelText || __( 'Document' );

// We don't care about this specific ref, but this is a way
// to get a ref within the editor canvas so we can focus it later.
const blockRef = useBlockRef( clientId );

/*
* Disable reason: The `list` ARIA role is redundant but
* Safari+VoiceOver won't announce the list otherwise.
Expand All @@ -60,7 +65,11 @@ function BlockBreadcrumb( { rootLabelText } ) {
<Button
className="block-editor-block-breadcrumb__button"
variant="tertiary"
onClick={ clearSelectedBlock }
onClick={ () => {
clearSelectedBlock();
// Focus the editor iframe.
blockRef.current?.closest( 'body' )?.focus();
} }
>
{ rootLabel }
</Button>
Expand Down

0 comments on commit 3901248

Please sign in to comment.