diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index 16b0e57505c69..ce2bed0d8837f 100644 --- a/packages/block-library/src/navigation/block.json +++ b/packages/block-library/src/navigation/block.json @@ -87,7 +87,6 @@ "showSubmenuIcon": "showSubmenuIcon", "openSubmenusOnClick": "openSubmenusOnClick", "style": "style", - "orientation": "orientation", "maxNestingLevel": "maxNestingLevel" }, "supports": { diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index 9fb672e5c557d..16cc4c014cf90 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -477,19 +477,6 @@ function Navigation( { showClassicMenuConversionNotice, ] ); - // Spacer block needs orientation from context. This is a patch until - // https://github.com/WordPress/gutenberg/issues/36197 is addressed. - useEffect( () => { - if ( orientation ) { - __unstableMarkNextChangeAsNotPersistent(); - setAttributes( { orientation } ); - } - }, [ - orientation, - __unstableMarkNextChangeAsNotPersistent, - setAttributes, - ] ); - useEffect( () => { if ( ! enableContrastChecking ) { return; diff --git a/packages/block-library/src/spacer/edit.js b/packages/block-library/src/spacer/edit.js index bdda226fdf927..2e9876aa0f6d0 100644 --- a/packages/block-library/src/spacer/edit.js +++ b/packages/block-library/src/spacer/edit.js @@ -78,8 +78,16 @@ const SpacerEdit = ( { setAttributes, toggleSelection, context, + __unstableParentLayout: parentLayout, } ) => { const { orientation } = context; + const { orientation: parentOrientation, type } = parentLayout || {}; + // If the spacer is inside a flex container, it should either inherit the orientation + // of the parent or use the flex default orientation. + const inheritedOrientation = + ! parentOrientation && type === 'flex' + ? 'horizontal' + : parentOrientation || orientation; const { height, width } = attributes; const [ isResizing, setIsResizing ] = useState( false ); @@ -104,13 +112,18 @@ const SpacerEdit = ( { const style = { height: - orientation === 'horizontal' + inheritedOrientation === 'horizontal' ? 24 : temporaryHeight || height || undefined, width: - orientation === 'horizontal' + inheritedOrientation === 'horizontal' ? temporaryWidth || width || undefined : undefined, + // In vertical flex containers, the spacer shrinks to nothing without a minimum width. + minWidth: + inheritedOrientation === 'vertical' && type === 'flex' + ? 48 + : undefined, }; const resizableBoxWithOrientation = ( blockOrientation ) => { @@ -166,7 +179,7 @@ const SpacerEdit = ( { }; useEffect( () => { - if ( orientation === 'horizontal' && ! width ) { + if ( inheritedOrientation === 'horizontal' && ! width ) { setAttributes( { height: '0px', width: '72px', @@ -177,13 +190,13 @@ const SpacerEdit = ( { return ( <> - { resizableBoxWithOrientation( orientation ) } + { resizableBoxWithOrientation( inheritedOrientation ) }