Skip to content

Commit 513ff93

Browse files
authored
Only show submenu options and Show arrow button when relevant. (#36826)
* only show submenu options when relevant * disable show arrow button when open on click on * rename found submenus variable
1 parent 8f38fa2 commit 513ff93

File tree

1 file changed

+37
-22
lines changed
  • packages/block-library/src/navigation/edit

1 file changed

+37
-22
lines changed

packages/block-library/src/navigation/edit/index.js

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,19 @@ function Navigation( {
134134
`navigationMenu/${ ref }`
135135
);
136136

137-
const { innerBlocks, isInnerBlockSelected } = useSelect(
137+
const { innerBlocks, isInnerBlockSelected, hasSubmenus } = useSelect(
138138
( select ) => {
139139
const { getBlocks, hasSelectedInnerBlock } = select(
140140
blockEditorStore
141141
);
142+
const blocks = getBlocks( clientId );
143+
const firstSubmenu = !! blocks.find(
144+
( block ) => block.name === 'core/navigation-submenu'
145+
);
146+
142147
return {
143-
innerBlocks: getBlocks( clientId ),
148+
hasSubmenus: firstSubmenu,
149+
innerBlocks: blocks,
144150
isInnerBlockSelected: hasSelectedInnerBlock( clientId, true ),
145151
};
146152
},
@@ -411,26 +417,35 @@ function Navigation( {
411417
label={ __( 'Always' ) }
412418
/>
413419
</ToggleGroupControl>
414-
<h3>{ __( 'Submenus' ) }</h3>
415-
<ToggleControl
416-
checked={ openSubmenusOnClick }
417-
onChange={ ( value ) => {
418-
setAttributes( {
419-
openSubmenusOnClick: value,
420-
} );
421-
} }
422-
label={ __( 'Open on click' ) }
423-
/>
424-
{ ! attributes.openSubmenusOnClick && (
425-
<ToggleControl
426-
checked={ showSubmenuIcon }
427-
onChange={ ( value ) => {
428-
setAttributes( {
429-
showSubmenuIcon: value,
430-
} );
431-
} }
432-
label={ __( 'Show icons' ) }
433-
/>
420+
{ hasSubmenus && (
421+
<>
422+
<h3>{ __( 'Submenus' ) }</h3>
423+
<ToggleControl
424+
checked={ openSubmenusOnClick }
425+
onChange={ ( value ) => {
426+
setAttributes( {
427+
openSubmenusOnClick: value,
428+
...( value && {
429+
showSubmenuIcon: true,
430+
} ), // Make sure arrows are shown when we toggle this on.
431+
} );
432+
} }
433+
label={ __( 'Open on click' ) }
434+
/>
435+
436+
<ToggleControl
437+
checked={ showSubmenuIcon }
438+
onChange={ ( value ) => {
439+
setAttributes( {
440+
showSubmenuIcon: value,
441+
} );
442+
} }
443+
disabled={
444+
attributes.openSubmenusOnClick
445+
}
446+
label={ __( 'Show arrow' ) }
447+
/>
448+
</>
434449
) }
435450
</PanelBody>
436451
) }

0 commit comments

Comments
 (0)