diff --git a/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js b/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js index f3d22e6557a674..73454768c06b04 100644 --- a/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js +++ b/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js @@ -9,7 +9,7 @@ import { import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { moreVertical } from '@wordpress/icons'; -import { Children, cloneElement, useCallback } from '@wordpress/element'; +import { Children, cloneElement } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { store as keyboardShortcutsStore, @@ -127,41 +127,35 @@ export function BlockSettingsDropdown( { const isMatch = __unstableUseShortcutEventMatch(); const hasSelectedBlocks = selectedBlockClientIds.length > 0; - const updateSelectionAfterDuplicate = useCallback( - async ( clientIdsPromise ) => { - if ( __experimentalSelectBlock ) { - const ids = await clientIdsPromise; - if ( ids && ids[ 0 ] ) { - __experimentalSelectBlock( ids[ 0 ], false ); - } - } - }, - [ __experimentalSelectBlock ] - ); + async function updateSelectionAfterDuplicate( clientIdsPromise ) { + if ( ! __experimentalSelectBlock ) { + return; + } - const updateSelectionAfterRemove = useCallback( () => { - if ( __experimentalSelectBlock ) { - let blockToFocus = previousBlockClientId || firstParentClientId; + const ids = await clientIdsPromise; + if ( ids && ids[ 0 ] ) { + __experimentalSelectBlock( ids[ 0 ], false ); + } + } - // Focus the first block if there's no previous block nor parent block. - if ( ! blockToFocus ) { - blockToFocus = getBlockOrder()[ 0 ]; - } + function updateSelectionAfterRemove() { + if ( ! __experimentalSelectBlock ) { + return; + } - // Only update the selection if the original selection is removed. - const shouldUpdateSelection = - hasSelectedBlocks && getSelectedBlockClientIds().length === 0; + let blockToFocus = previousBlockClientId || firstParentClientId; - __experimentalSelectBlock( blockToFocus, shouldUpdateSelection ); + // Focus the first block if there's no previous block nor parent block. + if ( ! blockToFocus ) { + blockToFocus = getBlockOrder()[ 0 ]; } - }, [ - __experimentalSelectBlock, - previousBlockClientId, - firstParentClientId, - getBlockOrder, - hasSelectedBlocks, - getSelectedBlockClientIds, - ] ); + + // Only update the selection if the original selection is removed. + const shouldUpdateSelection = + hasSelectedBlocks && getSelectedBlockClientIds().length === 0; + + __experimentalSelectBlock( blockToFocus, shouldUpdateSelection ); + } // This can occur when the selected block (the parent) // displays child blocks within a List View. @@ -179,20 +173,17 @@ export function BlockSettingsDropdown( { ? undefined : openedBlockSettingsMenu === currentClientId || false; - const onToggle = useCallback( - ( localOpen ) => { - if ( localOpen && openedBlockSettingsMenu !== currentClientId ) { - setOpenedBlockSettingsMenu( currentClientId ); - } else if ( - ! localOpen && - openedBlockSettingsMenu && - openedBlockSettingsMenu === currentClientId - ) { - setOpenedBlockSettingsMenu( undefined ); - } - }, - [ currentClientId, openedBlockSettingsMenu, setOpenedBlockSettingsMenu ] - ); + function onToggle( localOpen ) { + if ( localOpen && openedBlockSettingsMenu !== currentClientId ) { + setOpenedBlockSettingsMenu( currentClientId ); + } else if ( + ! localOpen && + openedBlockSettingsMenu && + openedBlockSettingsMenu === currentClientId + ) { + setOpenedBlockSettingsMenu( undefined ); + } + } return (