Skip to content

Commit

Permalink
only show submenu options when relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
vcanales committed Nov 24, 2021
1 parent fe7c3ae commit d77ed8c
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions packages/block-library/src/navigation/edit/index.js
Expand Up @@ -136,13 +136,19 @@ function Navigation( {
`navigationMenu/${ navigationMenuId }`
);

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 @@ -406,26 +412,30 @@ 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,
} );
} }
label={ __( 'Open on click' ) }
/>
{ ! attributes.openSubmenusOnClick && (
<ToggleControl
checked={ showSubmenuIcon }
onChange={ ( value ) => {
setAttributes( {
showSubmenuIcon: value,
} );
} }
label={ __( 'Show icons' ) }
/>
) }
</>
) }
</PanelBody>
) }
Expand Down

0 comments on commit d77ed8c

Please sign in to comment.