Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DFW: reset zombie state on unmount #67076

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
store as blockEditorStore,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import { useEffect } from '@wordpress/element';
import { useEffect, useState } from '@wordpress/element';
import { Button, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { next, previous } from '@wordpress/icons';
Expand All @@ -24,23 +24,24 @@ import { unlock } from '../../lock-unlock';

const { useHasBlockToolbar } = unlock( blockEditorPrivateApis );

export default function CollapsibleBlockToolbar( { isCollapsed, onToggle } ) {
export default function CollapsibleBlockToolbar() {
const { blockSelectionStart } = useSelect( ( select ) => {
return {
blockSelectionStart:
select( blockEditorStore ).getBlockSelectionStart(),
};
}, [] );
const hasBlockToolbar = useHasBlockToolbar();
const [ isCollapsed, setIsCollapsed ] = useState( false );

const hasBlockSelection = !! blockSelectionStart;

useEffect( () => {
// If we have a new block selection, show the block tools
if ( blockSelectionStart ) {
onToggle( false );
setIsCollapsed( false );
}
}, [ blockSelectionStart, onToggle ] );
ellatrix marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Should setIsCollapsed be passed in as a dependency here?

}, [ blockSelectionStart ] );

if ( ! hasBlockToolbar ) {
return null;
Expand All @@ -56,12 +57,11 @@ export default function CollapsibleBlockToolbar( { isCollapsed, onToggle } ) {
<BlockToolbar hideDragHandle />
</div>
<Popover.Slot name="block-toolbar" />

<Button
className="editor-collapsible-block-toolbar__toggle"
icon={ isCollapsed ? next : previous }
onClick={ () => {
onToggle( ! isCollapsed );
setIsCollapsed( ! isCollapsed );
} }
label={
isCollapsed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@
}
}

.editor-header__toolbar:has(.editor-collapsible-block-toolbar:not(.is-collapsed)) + .editor-header__center {
display: none;
}
Comment on lines +80 to +82
Copy link
Contributor

Choose a reason for hiding this comment

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

I’d put this in the parent component’s styles instead because this doesn’t apply to any elements of the component itself.

15 changes: 2 additions & 13 deletions packages/editor/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useSelect } from '@wordpress/data';
import { useMediaQuery, useViewportMatch } from '@wordpress/compose';
import { __unstableMotion as motion } from '@wordpress/components';
import { store as preferencesStore } from '@wordpress/preferences';
import { useState } from '@wordpress/element';
import { PinnedItems } from '@wordpress/interface';

/**
Expand Down Expand Up @@ -63,7 +62,6 @@ function Header( {
isPublishSidebarOpened,
showIconLabels,
hasFixedToolbar,
hasBlockSelection,
} = useSelect( ( select ) => {
const { get: getPreference } = select( preferencesStore );
const {
Expand Down Expand Up @@ -93,12 +91,6 @@ function Header( {
PATTERN_POST_TYPE,
].includes( postType );

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

const hasCenter =
( ! hasBlockSelection || isBlockToolsCollapsed ) &&
Copy link
Contributor

@talldan talldan Nov 27, 2024

Choose a reason for hiding this comment

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

Won't removing ! hasBlockSelection bring back the bug in #65824?

! isTooNarrowForDocumentBar;
const hasBackButton = useHasBackButton();
/*
* The edit-post-header classname is only kept for backward compatability
Expand All @@ -124,13 +116,10 @@ function Header( {
disableBlockTools={ forceDisableBlockTools || isTextEditor }
/>
{ hasFixedToolbar && isLargeViewport && (
<CollapsibleBlockToolbar
isCollapsed={ isBlockToolsCollapsed }
onToggle={ setIsBlockToolsCollapsed }
/>
<CollapsibleBlockToolbar />
) }
</motion.div>
{ hasCenter && (
{ ! isTooNarrowForDocumentBar && (
<motion.div
className="editor-header__center"
variants={ toolbarVariations }
Expand Down
Loading