Skip to content

Commit

Permalink
Add "Go to block" navigator menu action
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Jun 12, 2020
1 parent 85167ff commit fa5b9b0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
26 changes: 21 additions & 5 deletions packages/block-editor/src/components/block-navigation/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import classnames from 'classnames';
import {
__experimentalTreeGridCell as TreeGridCell,
__experimentalTreeGridItem as TreeGridItem,
MenuGroup,
MenuItem,
} from '@wordpress/components';

import { __ } from '@wordpress/i18n';
import { moreVertical } from '@wordpress/icons';
import { useState, useRef, useEffect } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -30,7 +33,7 @@ import { useBlockNavigationContext } from './context';
export default function BlockNavigationBlock( {
block,
isSelected,
selectBlock,
onClick,
position,
level,
rowCount,
Expand All @@ -41,6 +44,9 @@ export default function BlockNavigationBlock( {
const cellRef = useRef( null );
const [ isHovered, setIsHovered ] = useState( false );
const [ isFocused, setIsFocused ] = useState( false );
const { selectBlock: selectEditorBlock } = useDispatch(
'core/block-editor'
);
const { clientId } = block;

// Subtract 1 from rowCount, as it includes the block appender.
Expand Down Expand Up @@ -93,7 +99,7 @@ export default function BlockNavigationBlock( {
/>
<BlockNavigationBlockContents
block={ block }
onClick={ () => selectBlock( block.clientId ) }
onClick={ () => onClick( block.clientId ) }
isSelected={ isSelected }
position={ position }
siblingCount={ siblingCount }
Expand Down Expand Up @@ -151,8 +157,18 @@ export default function BlockNavigationBlock( {
onFocus,
} }
disableOpenOnArrowDown
__experimentalSelectBlock={ selectBlock }
/>
__experimentalSelectBlock={ onClick }
>
<MenuGroup>
<MenuItem
onClick={ () => {
selectEditorBlock( clientId );
} }
>
{ __( 'Go to block' ) }
</MenuItem>
</MenuGroup>
</BlockSettingsDropdown>
) }
</TreeGridCell>
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function BlockNavigationBranch( props ) {
<Fragment key={ clientId }>
<BlockNavigationBlock
block={ block }
selectBlock={ selectBlock }
onClick={ selectBlock }
isSelected={ selectedBlockClientId === clientId }
level={ level }
position={ position }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { useSelect } from '@wordpress/data';
import { moreHorizontal } from '@wordpress/icons';

import { useState, useCallback } from '@wordpress/element';
import { useCallback } from '@wordpress/element';
import { serialize } from '@wordpress/blocks';

/**
Expand All @@ -38,6 +38,7 @@ const POPOVER_PROPS = {
export function BlockSettingsDropdown( {
clientIds,
__experimentalSelectBlock,
children,
...props
} ) {
const blockClientIds = castArray( clientIds );
Expand All @@ -62,7 +63,6 @@ export function BlockSettingsDropdown( {
};
}, [] );

const [ hasCopied, setHasCopied ] = useState();
const updateSelection = useCallback(
__experimentalSelectBlock
? async ( clientIdsPromise ) => {
Expand Down Expand Up @@ -168,6 +168,7 @@ export function BlockSettingsDropdown( {
fillProps={ { onClose } }
clientIds={ clientIds }
/>
{ children }
<MenuGroup>
{ ! isLocked && (
<MenuItem
Expand Down

0 comments on commit fa5b9b0

Please sign in to comment.