Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions packages/editor/src/components/block-navigation/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Fragment } from '@wordpress/element';
import { IconButton, Dropdown, SVG, Path, KeyboardShortcuts } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { rawShortcut, displayShortcut } from '@wordpress/keycodes';
import { withSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -17,7 +18,7 @@ const MenuIcon = (
</SVG>
);

function BlockNavigationDropdown() {
function BlockNavigationDropdown( { hasBlocks } ) {
return (
<Dropdown
renderToggle={ ( { isOpen, onToggle } ) => (
Expand All @@ -31,10 +32,11 @@ function BlockNavigationDropdown() {
<IconButton
icon={ MenuIcon }
aria-expanded={ isOpen }
onClick={ onToggle }
onClick={ hasBlocks ? onToggle : undefined }
label={ __( 'Block Navigation' ) }
className="editor-block-navigation"
shortcut={ displayShortcut.access( 'o' ) }
aria-disabled={ ! hasBlocks }
/>
</Fragment>
) }
Expand All @@ -45,4 +47,8 @@ function BlockNavigationDropdown() {
);
}

export default BlockNavigationDropdown;
export default withSelect( ( select ) => {
return {
hasBlocks: !! select( 'core/editor' ).getBlockCount(),
};
} )( BlockNavigationDropdown );
11 changes: 4 additions & 7 deletions packages/editor/src/components/block-navigation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ function BlockNavigationList( {
}

function BlockNavigation( { rootBlock, rootBlocks, selectedBlockClientId, selectBlock } ) {
if ( ! rootBlocks || rootBlocks.length === 0 ) {
return null;
}

const hasHierarchy = (
rootBlock && (
rootBlock.clientId !== selectedBlockClientId ||
Expand Down Expand Up @@ -95,13 +99,6 @@ function BlockNavigation( { rootBlock, rootBlocks, selectedBlockClientId, select
selectBlock={ selectBlock }
/>
) }
{ ( ! rootBlocks || rootBlocks.length === 0 ) && (
// If there are no blocks in this document, don't render a list of blocks.
// Instead: inform the user no blocks exist yet.
<p className="editor-block-navigation__paragraph">
{ __( 'No blocks created yet.' ) }
</p>
) }
</NavigableMenu>
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/table-of-contents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ function TableOfContents( { hasBlocks } ) {
contentClassName="table-of-contents__popover"
renderToggle={ ( { isOpen, onToggle } ) => (
<IconButton
onClick={ onToggle }
onClick={ hasBlocks ? onToggle : undefined }
icon="info-outline"
aria-expanded={ isOpen }
label={ __( 'Content structure' ) }
labelPosition="bottom"
disabled={ ! hasBlocks }
aria-disabled={ ! hasBlocks }
/>
) }
renderContent={ () => <TableOfContentsPanel /> }
Expand Down
11 changes: 0 additions & 11 deletions test/e2e/specs/block-hierarchy-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,4 @@ describe( 'Navigating the block hierarchy', () => {

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should report "No blocks created yet." when post is empty', async () => {
await openBlockNavigator();

const blockNavigationText = await page.$eval(
'.editor-block-navigation__paragraph',
( navigationParagraph ) => navigationParagraph.textContent
);

expect( blockNavigationText ).toEqual( 'No blocks created yet.' );
} );
} );