From 20f35ddd8ad178ce0ee086048fed86300fdd5267 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Thu, 3 Oct 2024 19:37:22 +0800 Subject: [PATCH] Top Toolbar: Show document bar when no block is selected even if block tools are expanded (#65839) * Top Toolbar: Show document bar when no block is selected even if block tools are expanded * Change variable name to hasBlockSelection ---- Co-authored-by: talldan Co-authored-by: andrewserong Co-authored-by: eatse21 --- packages/editor/src/components/header/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/components/header/index.js b/packages/editor/src/components/header/index.js index f49ada48997ce..631643f26d4d5 100644 --- a/packages/editor/src/components/header/index.js +++ b/packages/editor/src/components/header/index.js @@ -1,6 +1,7 @@ /** * WordPress dependencies */ +import { store as blockEditorStore } from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; import { useMediaQuery, useViewportMatch } from '@wordpress/compose'; import { __unstableMotion as motion } from '@wordpress/components'; @@ -52,12 +53,13 @@ function Header( { const isLargeViewport = useViewportMatch( 'medium' ); const isTooNarrowForDocumentBar = useMediaQuery( '(max-width: 403px)' ); const { + postType, isTextEditor, isPublishSidebarOpened, showIconLabels, hasFixedToolbar, + hasBlockSelection, isNestedEntity, - postType, } = useSelect( ( select ) => { const { get: getPreference } = select( preferencesStore ); const { @@ -73,6 +75,8 @@ function Header( { isPublishSidebarOpened: _isPublishSidebarOpened(), showIconLabels: getPreference( 'core', 'showIconLabels' ), hasFixedToolbar: getPreference( 'core', 'fixedToolbar' ), + hasBlockSelection: + !! select( blockEditorStore ).getBlockSelectionStart(), isNestedEntity: !! getEditorSettings().onNavigateToPreviousEntityRecord, }; @@ -85,7 +89,9 @@ function Header( { const [ isBlockToolsCollapsed, setIsBlockToolsCollapsed ] = useState( true ); - const hasCenter = isBlockToolsCollapsed && ! isTooNarrowForDocumentBar; + const hasCenter = + ( ! hasBlockSelection || isBlockToolsCollapsed ) && + ! isTooNarrowForDocumentBar; const hasBackButton = useHasBackButton(); /* * The edit-post-header classname is only kept for backward compatability