Skip to content
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

Only show submenu options and Show arrow button when relevant. #36826

Merged
merged 3 commits into from Nov 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 37 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,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