From 06b0f1ad95debec4c4ca2b1c4afe380007934832 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Thu, 14 Dec 2023 10:52:09 +0200 Subject: [PATCH] Fix BlockSwitcher checks for showing a Dropdown menu or not --- .../src/components/block-switcher/index.js | 108 ++++++++---------- 1 file changed, 49 insertions(+), 59 deletions(-) diff --git a/packages/block-editor/src/components/block-switcher/index.js b/packages/block-editor/src/components/block-switcher/index.js index 0960dc87eaa499..8117c6f539b4f3 100644 --- a/packages/block-editor/src/components/block-switcher/index.js +++ b/packages/block-editor/src/components/block-switcher/index.js @@ -138,11 +138,14 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => { const hasPossibleBlockVariationTransformations = !! blockVariationTransformations?.length; const hasPatternTransformation = !! patterns?.length && canRemove; - if ( - ! hasBlockStyles && - ! hasPossibleBlockTransformations && - ! hasPossibleBlockVariationTransformations - ) { + const hasBlockOrBlockVariationTransforms = + hasPossibleBlockTransformations || + hasPossibleBlockVariationTransformations; + const showDropdown = + hasBlockStyles || + hasBlockOrBlockVariationTransforms || + hasPatternTransformation; + if ( ! showDropdown ) { return ( { blocks.length ); - const hasBlockOrBlockVariationTransforms = - hasPossibleBlockTransformations || - hasPossibleBlockVariationTransformations; - const showDropDown = - hasBlockStyles || - hasBlockOrBlockVariationTransforms || - hasPatternTransformation; return ( @@ -218,54 +214,48 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => { } } menuProps={ { orientation: 'both' } } > - { ( { onClose } ) => - showDropDown && ( -
- { hasPatternTransformation && ( - ( +
+ { hasPatternTransformation && ( + { + onPatternTransform( transformedBlocks - ) => { - onPatternTransform( - transformedBlocks - ); - onClose(); - } } - /> - ) } - { hasBlockOrBlockVariationTransforms && ( - { - onBlockTransform( name ); - onClose(); - } } - onSelectVariation={ ( name ) => { - onBlockVariationTransform( - name - ); - onClose(); - } } - /> - ) } - { hasBlockStyles && ( - - ) } -
- ) - } + ); + onClose(); + } } + /> + ) } + { hasBlockOrBlockVariationTransforms && ( + { + onBlockTransform( name ); + onClose(); + } } + onSelectVariation={ ( name ) => { + onBlockVariationTransform( name ); + onClose(); + } } + /> + ) } + { hasBlockStyles && ( + + ) } +
+ ) } ) }