Skip to content

Commit

Permalink
Top Toolbar: Fix 'collapsed' state synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Feb 22, 2024
1 parent efe7d2e commit 5b32de9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 9 additions & 6 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {
const blockToolbarRef = useRef();
const {
isTextEditor,
hasBlockSelection,
blockSelectionStart,
hasActiveMetaboxes,
hasFixedToolbar,
isPublishSidebarOpened,
Expand All @@ -73,8 +73,8 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {

return {
isTextEditor: getEditorMode() === 'text',
hasBlockSelection:
!! select( blockEditorStore ).getBlockSelectionStart(),
blockSelectionStart:
select( blockEditorStore ).getBlockSelectionStart(),
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
hasHistory:
!! select( editorStore ).getEditorSettings()
Expand All @@ -88,13 +88,14 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {

const [ isBlockToolsCollapsed, setIsBlockToolsCollapsed ] =
useState( true );
const hasBlockSelection = !! blockSelectionStart;

useEffect( () => {
// If we have a new block selection, show the block tools
if ( hasBlockSelection ) {
if ( blockSelectionStart ) {
setIsBlockToolsCollapsed( false );
}
}, [ hasBlockSelection ] );
}, [ blockSelectionStart ] );

return (
<div className="edit-post-header">
Expand All @@ -121,7 +122,9 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {
className={ classnames(
'selected-block-tools-wrapper',
{
'is-collapsed': isBlockToolsCollapsed,
'is-collapsed':
isBlockToolsCollapsed ||
! hasBlockSelection,
}
) }
>
Expand Down
4 changes: 3 additions & 1 deletion packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ export default function HeaderEditMode() {
className={ classnames(
'selected-block-tools-wrapper',
{
'is-collapsed': isBlockToolsCollapsed,
'is-collapsed':
isBlockToolsCollapsed ||
! hasBlockSelected,
}
) }
>
Expand Down

0 comments on commit 5b32de9

Please sign in to comment.