From db6f1a0ef2c883e95741d8c3c95630b9719bc3e4 Mon Sep 17 00:00:00 2001 From: Ella Date: Mon, 18 Nov 2024 13:04:55 +0100 Subject: [PATCH 1/4] DFW: reset zombie state on unmount --- .../src/components/collapsible-block-toolbar/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/editor/src/components/collapsible-block-toolbar/index.js b/packages/editor/src/components/collapsible-block-toolbar/index.js index cafbfecb72516..a259e61e2dc2b 100644 --- a/packages/editor/src/components/collapsible-block-toolbar/index.js +++ b/packages/editor/src/components/collapsible-block-toolbar/index.js @@ -42,6 +42,14 @@ export default function CollapsibleBlockToolbar( { isCollapsed, onToggle } ) { } }, [ blockSelectionStart, onToggle ] ); + // Reset isCollapsed when the collapsible block toolbar unmounts. + useEffect( + () => () => { + onToggle( true ); + }, + [ onToggle ] + ); + if ( ! hasBlockToolbar ) { return null; } From d6d4c2ddb83bc5c9e90bf6dea707f96c0cf3fcec Mon Sep 17 00:00:00 2001 From: Ella Date: Mon, 18 Nov 2024 13:11:40 +0100 Subject: [PATCH 2/4] improve comment --- .../editor/src/components/collapsible-block-toolbar/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/components/collapsible-block-toolbar/index.js b/packages/editor/src/components/collapsible-block-toolbar/index.js index a259e61e2dc2b..d6f1542f68490 100644 --- a/packages/editor/src/components/collapsible-block-toolbar/index.js +++ b/packages/editor/src/components/collapsible-block-toolbar/index.js @@ -42,7 +42,8 @@ export default function CollapsibleBlockToolbar( { isCollapsed, onToggle } ) { } }, [ blockSelectionStart, onToggle ] ); - // Reset isCollapsed when the collapsible block toolbar unmounts. + // Reset isCollapsed when the collapsible block toolbar unmounts. It is true + // by default. useEffect( () => () => { onToggle( true ); From ee499273966ec10717e07939a4550d0a1a012909 Mon Sep 17 00:00:00 2001 From: Ella Date: Mon, 18 Nov 2024 13:38:58 +0100 Subject: [PATCH 3/4] use css --- .../collapsible-block-toolbar/index.js | 24 ++++--------------- .../collapsible-block-toolbar/style.scss | 3 +++ .../editor/src/components/header/index.js | 15 ++---------- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/packages/editor/src/components/collapsible-block-toolbar/index.js b/packages/editor/src/components/collapsible-block-toolbar/index.js index d6f1542f68490..131364d9417d2 100644 --- a/packages/editor/src/components/collapsible-block-toolbar/index.js +++ b/packages/editor/src/components/collapsible-block-toolbar/index.js @@ -11,7 +11,7 @@ import { store as blockEditorStore, privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; -import { useEffect } from '@wordpress/element'; +import { useState } from '@wordpress/element'; import { Button, Popover } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { next, previous } from '@wordpress/icons'; @@ -24,7 +24,7 @@ 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: @@ -32,25 +32,10 @@ export default function CollapsibleBlockToolbar( { isCollapsed, onToggle } ) { }; }, [] ); 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 ); - } - }, [ blockSelectionStart, onToggle ] ); - - // Reset isCollapsed when the collapsible block toolbar unmounts. It is true - // by default. - useEffect( - () => () => { - onToggle( true ); - }, - [ onToggle ] - ); - if ( ! hasBlockToolbar ) { return null; } @@ -65,12 +50,11 @@ export default function CollapsibleBlockToolbar( { isCollapsed, onToggle } ) { -