Skip to content

Commit

Permalink
Pass correct rootClientId to the inserter
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Aug 28, 2020
1 parent cefab03 commit 1e2b9bf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/edit-widgets/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useSelect } from '@wordpress/data';
import SaveButton from '../save-button';
import UndoButton from './undo-redo/undo';
import RedoButton from './undo-redo/redo';
import { buildWidgetAreasPostId, KIND, POST_TYPE } from '../../store/utils';

const inserterToggleProps = { isPrimary: true };

Expand All @@ -27,7 +28,21 @@ function Header( { isCustomizer } ) {
const { getBlockRootClientId, getBlockSelectionEnd } = select(
'core/block-editor'
);
return getBlockRootClientId( getBlockSelectionEnd() );
const selectedRootId = getBlockRootClientId( getBlockSelectionEnd() );
if ( selectedRootId ) {
return selectedRootId;
}

// Default to the first widget area
const { getEntityRecord } = select( 'core' );
const widgetAreasPost = getEntityRecord(
KIND,
POST_TYPE,
buildWidgetAreasPostId()
);
if ( widgetAreasPost ) {
return widgetAreasPost?.blocks[ 0 ]?.clientId;
}
}, [] );

return (
Expand Down

0 comments on commit 1e2b9bf

Please sign in to comment.