Skip to content
Merged
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
fix: use active variation as the parent block if available
  • Loading branch information
dinhtungdu committed Sep 30, 2022
commit 4da8655fac31f36a42f976926701d8712a075c56
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { castArray } from 'lodash';
/**
* WordPress dependencies
*/
import { getBlockType, serialize } from '@wordpress/blocks';
import {
getBlockType,
serialize,
store as blocksStore,
} from '@wordpress/blocks';
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { moreVertical } from '@wordpress/icons';
Expand Down Expand Up @@ -75,8 +79,11 @@ export function BlockSettingsDropdown( {
getNextBlockClientId,
getSelectedBlockClientIds,
getSettings,
getBlockAttributes,
} = select( blockEditorStore );

const { getActiveBlockVariation } = select( blocksStore );

const parents = getBlockParents( firstBlockClientId );
const _firstParentClientId = parents[ parents.length - 1 ];
const parentBlockName = getBlockName( _firstParentClientId );
Expand All @@ -85,7 +92,11 @@ export function BlockSettingsDropdown( {
firstParentClientId: _firstParentClientId,
hasReducedUI: getSettings().hasReducedUI,
onlyBlock: 1 === getBlockCount(),
parentBlockType: getBlockType( parentBlockName ),
parentBlockType:
getActiveBlockVariation(
parentBlockName,
getBlockAttributes( _firstParentClientId )
) || getBlockType( parentBlockName ),
previousBlockClientId:
getPreviousBlockClientId( firstBlockClientId ),
nextBlockClientId: getNextBlockClientId( firstBlockClientId ),
Expand Down