From d77ed8ca1d43eaaf97088c4a1688c69e017100da Mon Sep 17 00:00:00 2001 From: Vicente Canales Date: Wed, 24 Nov 2021 11:51:05 -0300 Subject: [PATCH 1/3] only show submenu options when relevant --- .../src/navigation/edit/index.js | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index be6f58e1ea875..9bea01a768ba1 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -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 ), }; }, @@ -406,26 +412,30 @@ function Navigation( { label={ __( 'Always' ) } /> -

{ __( 'Submenus' ) }

- { - setAttributes( { - openSubmenusOnClick: value, - } ); - } } - label={ __( 'Open on click' ) } - /> - { ! attributes.openSubmenusOnClick && ( - { - setAttributes( { - showSubmenuIcon: value, - } ); - } } - label={ __( 'Show icons' ) } - /> + { hasSubmenus && ( + <> +

{ __( 'Submenus' ) }

+ { + setAttributes( { + openSubmenusOnClick: value, + } ); + } } + label={ __( 'Open on click' ) } + /> + { ! attributes.openSubmenusOnClick && ( + { + setAttributes( { + showSubmenuIcon: value, + } ); + } } + label={ __( 'Show icons' ) } + /> + ) } + ) } ) } From 1e5cfa6cc10f26eacee39f0d6ab58b994bcbd82f Mon Sep 17 00:00:00 2001 From: Vicente Canales Date: Wed, 24 Nov 2021 11:56:09 -0300 Subject: [PATCH 2/3] disable show arrow button when open on click on --- .../src/navigation/edit/index.js | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index 9bea01a768ba1..b8612b00a8cf0 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -142,12 +142,12 @@ function Navigation( { blockEditorStore ); const blocks = getBlocks( clientId ); - const firstSubmenu = blocks.find( + const didFindSubmenu = !! blocks.find( ( block ) => block.name === 'core/navigation-submenu' ); return { - hasSubmenus: !! firstSubmenu, + hasSubmenus: didFindSubmenu, innerBlocks: blocks, isInnerBlockSelected: hasSelectedInnerBlock( clientId, true ), }; @@ -420,21 +420,26 @@ function Navigation( { onChange={ ( value ) => { setAttributes( { openSubmenusOnClick: value, + ...( value && { + showSubmenuIcon: true, + } ), // make sure arrows are shown when we toggle this on. } ); } } label={ __( 'Open on click' ) } /> - { ! attributes.openSubmenusOnClick && ( - { - setAttributes( { - showSubmenuIcon: value, - } ); - } } - label={ __( 'Show icons' ) } - /> - ) } + + { + setAttributes( { + showSubmenuIcon: value, + } ); + } } + disabled={ + attributes.openSubmenusOnClick + } + label={ __( 'Show arrow' ) } + /> ) } From 11f01f0f1285f9abaea7bc390eee0aea777b9ee3 Mon Sep 17 00:00:00 2001 From: Vicente Canales Date: Fri, 26 Nov 2021 10:35:55 -0300 Subject: [PATCH 3/3] rename found submenus variable --- packages/block-library/src/navigation/edit/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index b8612b00a8cf0..9b35ea397ab7a 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -142,12 +142,12 @@ function Navigation( { blockEditorStore ); const blocks = getBlocks( clientId ); - const didFindSubmenu = !! blocks.find( + const firstSubmenu = !! blocks.find( ( block ) => block.name === 'core/navigation-submenu' ); return { - hasSubmenus: didFindSubmenu, + hasSubmenus: firstSubmenu, innerBlocks: blocks, isInnerBlockSelected: hasSelectedInnerBlock( clientId, true ), }; @@ -422,7 +422,7 @@ function Navigation( { openSubmenusOnClick: value, ...( value && { showSubmenuIcon: true, - } ), // make sure arrows are shown when we toggle this on. + } ), // Make sure arrows are shown when we toggle this on. } ); } } label={ __( 'Open on click' ) }