Skip to content

Commit

Permalink
Stop auto-focusing Navigation block in Navigation screen. (#25592)
Browse files Browse the repository at this point in the history
I also added a JSDoc comment while I was at it.
  • Loading branch information
ZebulanStanphill committed Sep 24, 2020
1 parent ea266a5 commit a7f1991
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions packages/edit-navigation/src/components/editor/block-view.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { WritingFlow, ObserveTyping, BlockList } from '@wordpress/block-editor';
import { BlockList, ObserveTyping, WritingFlow } from '@wordpress/block-editor';
import { Spinner } from '@wordpress/components';

/**
* The current navigation rendered in the form of a core Navigation block.
*
* @param {Object} props Component props.
* @param {boolean} props.isPending Whether the navigation post has loaded.
*/
export default function BlockView( { isPending } ) {
const rootClientId = useSelect(
( select ) => select( 'core/block-editor' ).getBlocks()[ 0 ]?.clientId,
[]
);

const { selectBlock } = useDispatch( 'core/block-editor' );

// Select the root Navigation block when it becomes available.
useEffect( () => {
if ( rootClientId ) {
selectBlock( rootClientId );
}
}, [ rootClientId, selectBlock ] );

return (
<div className="edit-navigation-editor__block-view">
{ isPending ? (
Expand Down

0 comments on commit a7f1991

Please sign in to comment.