Skip to content

Commit

Permalink
Improve top bar tools interaction consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Nov 22, 2018
1 parent 9cc03c0 commit 675eb15
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
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 @@ -74,6 +74,10 @@ function BlockNavigation( { rootBlock, rootBlocks, selectedBlockClientId, select
)
);

if ( ! rootBlocks || rootBlocks.length === 0 ) {
return null;
}

return (
<NavigableMenu
role="presentation"
Expand All @@ -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.' );
} );
} );

0 comments on commit 675eb15

Please sign in to comment.