diff --git a/packages/block-library/src/paragraph/edit.js b/packages/block-library/src/paragraph/edit.js index 597ddc38ddeb3..0d12b7f8e4d7d 100644 --- a/packages/block-library/src/paragraph/edit.js +++ b/packages/block-library/src/paragraph/edit.js @@ -150,7 +150,6 @@ class ParagraphBlock extends Component { { setAttributes( { align: nextAlign } ); diff --git a/packages/editor/src/components/alignment-toolbar/index.js b/packages/editor/src/components/alignment-toolbar/index.js index 87bff9fee249d..a44cba3ae67b6 100644 --- a/packages/editor/src/components/alignment-toolbar/index.js +++ b/packages/editor/src/components/alignment-toolbar/index.js @@ -9,6 +9,13 @@ import { find } from 'lodash'; import { __ } from '@wordpress/i18n'; import { Toolbar } from '@wordpress/components'; import { withViewportMatch } from '@wordpress/viewport'; +import { withSelect } from '@wordpress/data'; +import { compose } from '@wordpress/compose'; + +/** + * Internal dependencies + */ +import { withBlockEditContext } from '../block-edit/context'; const ALIGNMENT_CONTROLS = [ { @@ -28,7 +35,7 @@ const ALIGNMENT_CONTROLS = [ }, ]; -function AlignmentToolbar( { isCollapsed, isLargeViewport, value, onChange } ) { +function AlignmentToolbar( { isCollapsed, value, onChange } ) { function applyOrUnset( align ) { return () => onChange( value === align ? undefined : align ); } @@ -37,7 +44,7 @@ function AlignmentToolbar( { isCollapsed, isLargeViewport, value, onChange } ) { return ( { @@ -54,4 +61,20 @@ function AlignmentToolbar( { isCollapsed, isLargeViewport, value, onChange } ) { ); } -export default withViewportMatch( { isLargeViewport: 'medium' } )( AlignmentToolbar ); +export default compose( + withBlockEditContext( ( { clientId } ) => { + return { + clientId, + }; + } ), + withViewportMatch( { isLargeViewport: 'medium' } ), + withSelect( ( select, { clientId, isLargeViewport, isCollapsed } ) => { + const { getBlockRootClientId, getEditorSettings } = select( 'core/editor' ); + return { + isCollapsed: isCollapsed || ! isLargeViewport || ( + getBlockRootClientId( clientId ) && + ! getEditorSettings().hasFixedToolbar + ), + }; + } ), +)( AlignmentToolbar );