Skip to content

Commit

Permalink
Top Toolbar: Show document bar when no block is selected even if bloc…
Browse files Browse the repository at this point in the history
…k 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 <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: eatse21 <[email protected]>
  • Loading branch information
4 people authored and gutenbergplugin committed Oct 3, 2024
1 parent 7d60169 commit 37e4dca
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/editor/src/components/header/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -53,10 +54,12 @@ function Header( {
const isLargeViewport = useViewportMatch( 'medium' );
const isTooNarrowForDocumentBar = useMediaQuery( '(max-width: 403px)' );
const {
postType,
isTextEditor,
isPublishSidebarOpened,
showIconLabels,
hasFixedToolbar,
hasBlockSelection,
isNestedEntity,
} = useSelect( ( select ) => {
const { get: getPreference } = select( preferencesStore );
Expand All @@ -72,6 +75,8 @@ function Header( {
isPublishSidebarOpened: _isPublishSidebarOpened(),
showIconLabels: getPreference( 'core', 'showIconLabels' ),
hasFixedToolbar: getPreference( 'core', 'fixedToolbar' ),
hasBlockSelection:
!! select( blockEditorStore ).getBlockSelectionStart(),
isNestedEntity:
!! getEditorSettings().onNavigateToPreviousEntityRecord,
isZoomedOutView: __unstableGetEditorMode() === 'zoom-out',
Expand All @@ -81,7 +86,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 compatibilty
Expand Down

0 comments on commit 37e4dca

Please sign in to comment.