diff --git a/packages/block-editor/src/components/block-editing-mode/index.js b/packages/block-editor/src/components/block-editing-mode/index.js index 0347a9b7378d0e..bdd6ff971c1a4a 100644 --- a/packages/block-editor/src/components/block-editing-mode/index.js +++ b/packages/block-editor/src/components/block-editing-mode/index.js @@ -40,13 +40,20 @@ import { BlockListBlockContext } from '../block-list/block-list-block-context'; * * If called outside of a block context, the mode is applied to all blocks. * - * @param {?BlockEditingMode} mode The editing mode to apply. If undefined, the - * current editing mode is not changed. + * @param {?BlockEditingMode} mode The editing mode to apply. If undefined, the + * current editing mode is not changed. + * @param {?string} clientId The block client ID. * * @return {BlockEditingMode} The current editing mode. */ -export function useBlockEditingMode( mode ) { - const { clientId = '' } = useContext( BlockListBlockContext ) ?? {}; +export function useBlockEditingMode( mode, clientId ) { + const blockContextAll = useContext( BlockListBlockContext ) ?? {}; + const { clientId: contextClientId = '' } = blockContextAll; + + if ( ! clientId ) { + clientId = contextClientId; + } + const blockEditingMode = useSelect( ( select ) => unlock( select( blockEditorStore ) ).getBlockEditingMode( @@ -66,6 +73,6 @@ export function useBlockEditingMode( mode ) { unsetBlockEditingMode( clientId ); } }; - }, [ clientId, mode ] ); + }, [ clientId, mode, setBlockEditingMode, unsetBlockEditingMode ] ); return blockEditingMode; }