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 2 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 didFindSubmenu = !! blocks.find(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something about the variable "didFindSubmenu" feels curious to me. Could it just be called "submenus"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasSubmenus

Copy link
Member Author

@vcanales vcanales Nov 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use hasSubmenus because that's how I named the variable in the outer scope; I'll go with foundSubmenu, as it describes what the line is doing; using find to figure out if there's at least one submenu present.

( block ) => block.name === 'core/navigation-submenu'
);

return {
innerBlocks: getBlocks( clientId ),
hasSubmenus: didFindSubmenu,
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.
vcanales marked this conversation as resolved.
Show resolved Hide resolved
} );
} }
label={ __( 'Open on click' ) }
/>

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