Skip to content

Commit

Permalink
Top Toolbar: Fix 'collapsed' state synchronization (#59267)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: jeryj <[email protected]>
  • Loading branch information
4 people committed Feb 22, 2024
1 parent 2458eb6 commit 6e9dca5
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

1 comment on commit 6e9dca5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 6e9dca5.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8003575251
📝 Reported issues:

Please sign in to comment.