Skip to content

Commit

Permalink
Only show submenu options and Show arrow button when relevant. (#36826)
Browse files Browse the repository at this point in the history
* only show submenu options when relevant

* disable show arrow button when open on click on

* rename found submenus variable
  • Loading branch information
vcanales committed Nov 26, 2021
1 parent 8f38fa2 commit 513ff93
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions packages/block-library/src/navigation/edit/index.js
Expand Up @@ -134,13 +134,19 @@ function Navigation( {
`navigationMenu/${ ref }`
);

const { innerBlocks, isInnerBlockSelected } = useSelect(
const { innerBlocks, isInnerBlockSelected, hasSubmenus } = useSelect(
( select ) => {
const { getBlocks, hasSelectedInnerBlock } = select(
blockEditorStore
);
const blocks = getBlocks( clientId );
const firstSubmenu = !! blocks.find(
( block ) => block.name === 'core/navigation-submenu'
);

return {
innerBlocks: getBlocks( clientId ),
hasSubmenus: firstSubmenu,
innerBlocks: blocks,
isInnerBlockSelected: hasSelectedInnerBlock( clientId, true ),
};
},
Expand Down Expand Up @@ -411,26 +417,35 @@ function Navigation( {
label={ __( 'Always' ) }
/>
</ToggleGroupControl>
<h3>{ __( 'Submenus' ) }</h3>
<ToggleControl
checked={ openSubmenusOnClick }
onChange={ ( value ) => {
setAttributes( {
openSubmenusOnClick: value,
} );
} }
label={ __( 'Open on click' ) }
/>
{ ! attributes.openSubmenusOnClick && (
<ToggleControl
checked={ showSubmenuIcon }
onChange={ ( value ) => {
setAttributes( {
showSubmenuIcon: value,
} );
} }
label={ __( 'Show icons' ) }
/>
{ hasSubmenus && (
<>
<h3>{ __( 'Submenus' ) }</h3>
<ToggleControl
checked={ openSubmenusOnClick }
onChange={ ( value ) => {
setAttributes( {
openSubmenusOnClick: value,
...( value && {
showSubmenuIcon: true,
} ), // Make sure arrows are shown when we toggle this on.
} );
} }
label={ __( 'Open on click' ) }
/>

<ToggleControl
checked={ showSubmenuIcon }
onChange={ ( value ) => {
setAttributes( {
showSubmenuIcon: value,
} );
} }
disabled={
attributes.openSubmenusOnClick
}
label={ __( 'Show arrow' ) }
/>
</>
) }
</PanelBody>
) }
Expand Down

0 comments on commit 513ff93

Please sign in to comment.