-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the Blocks navigation a nested list to better communicate the blocks nesting level #11734
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import classnames from 'classnames'; | |
* WordPress dependencies | ||
*/ | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { MenuItem, MenuGroup } from '@wordpress/components'; | ||
import { Button, NavigableMenu } from '@wordpress/components'; | ||
import { getBlockType } from '@wordpress/blocks'; | ||
import { compose } from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
@@ -25,23 +25,30 @@ function BlockNavigationList( { | |
showNestedBlocks, | ||
} ) { | ||
return ( | ||
<ul className="editor-block-navigation__list" role="presentation"> | ||
/* | ||
* Disable reason: The `list` ARIA role is redundant but | ||
* Safari+VoiceOver won't announce the list otherwise. | ||
*/ | ||
/* eslint-disable jsx-a11y/no-redundant-roles */ | ||
<ul className="editor-block-navigation__list" role="list"> | ||
{ map( blocks, ( block ) => { | ||
const blockType = getBlockType( block.name ); | ||
const isSelected = block.clientId === selectedBlockClientId; | ||
|
||
return ( | ||
<li key={ block.clientId } role="presentation"> | ||
<div role="presentation" className="editor-block-navigation__item"> | ||
<MenuItem | ||
<li key={ block.clientId }> | ||
<div className="editor-block-navigation__item"> | ||
<Button | ||
className={ classnames( 'editor-block-navigation__item-button', { | ||
'is-selected': block.clientId === selectedBlockClientId, | ||
} ) } | ||
onClick={ () => selectBlock( block.clientId ) } | ||
isSelected={ block.clientId === selectedBlockClientId } | ||
role="menuitemradio" | ||
isSelected={ isSelected } | ||
> | ||
<BlockIcon icon={ blockType.icon } showColors /> | ||
{ blockType.title } | ||
</MenuItem> | ||
{ isSelected && <span className="screen-reader-text">{ __( '(selected block)' ) }</span> } | ||
</Button> | ||
</div> | ||
{ showNestedBlocks && !! block.innerBlocks && !! block.innerBlocks.length && ( | ||
<BlockNavigationList | ||
|
@@ -55,6 +62,7 @@ function BlockNavigationList( { | |
); | ||
} ) } | ||
</ul> | ||
/* eslint-enable jsx-a11y/no-redundant-roles */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not a big deal, but can this be moved immediately underneath the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried and I'd need to do something like this to make the linter happy:
not sure it looks so nice 🙂 |
||
); | ||
} | ||
|
||
|
@@ -67,7 +75,11 @@ function BlockNavigation( { rootBlock, rootBlocks, selectedBlockClientId, select | |
); | ||
|
||
return ( | ||
<MenuGroup label={ __( 'Block Navigation' ) }> | ||
<NavigableMenu | ||
role="presentation" | ||
className="editor-block-navigation__container" | ||
> | ||
<p className="editor-block-navigation__label">{ __( 'Block Navigation' ) }</p> | ||
{ hasHierarchy && ( | ||
<BlockNavigationList | ||
blocks={ [ rootBlock ] } | ||
|
@@ -90,7 +102,7 @@ function BlockNavigation( { rootBlock, rootBlocks, selectedBlockClientId, select | |
{ __( 'No blocks created yet.' ) } | ||
</p> | ||
) } | ||
</MenuGroup> | ||
</NavigableMenu> | ||
); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ for the explanation.
If there's a WebKit bug we could link to that'd be swell, but no worries if not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. It's a Safari specific bug. Chrome is exempt. I wouldn't know where to look for Apple open bugs. We do the same thing in
BlockTypesList
, for more details see #7058 (comment). Test case: https://codepen.io/afercia/full/WxmJWx/