From 349240ac3ea4890f0a95b07e4d089b4307a6eab7 Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Tue, 20 Sep 2022 17:51:09 +0900 Subject: [PATCH] Consider variations in the block title and label (#44250) --- .../src/components/block-list/use-block-props/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-list/use-block-props/index.js b/packages/block-editor/src/components/block-list/use-block-props/index.js index 3a02a400b9951a..ca6bb4355f52db 100644 --- a/packages/block-editor/src/components/block-list/use-block-props/index.js +++ b/packages/block-editor/src/components/block-list/use-block-props/index.js @@ -11,6 +11,7 @@ import { __, sprintf } from '@wordpress/i18n'; import { __unstableGetBlockProps as getBlockProps, getBlockType, + store as blocksStore, } from '@wordpress/blocks'; import { useMergeRefs, useDisabled } from '@wordpress/compose'; import { useSelect } from '@wordpress/data'; @@ -77,6 +78,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) { } = useSelect( ( select ) => { const { + getBlockAttributes, getBlockIndex, getBlockMode, getBlockName, @@ -87,19 +89,22 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) { isAncestorMultiSelected, isFirstMultiSelectedBlock, } = select( blockEditorStore ); + const { getActiveBlockVariation } = select( blocksStore ); const isSelected = isBlockSelected( clientId ); const isPartOfMultiSelection = isBlockMultiSelected( clientId ) || isAncestorMultiSelected( clientId ); const blockName = getBlockName( clientId ); const blockType = getBlockType( blockName ); + const attributes = getBlockAttributes( clientId ); + const match = getActiveBlockVariation( blockName, attributes ); return { index: getBlockIndex( clientId ), mode: getBlockMode( clientId ), name: blockName, blockApiVersion: blockType?.apiVersion || 1, - blockTitle: blockType?.title, + blockTitle: match?.title || blockType?.title, isPartOfSelection: isSelected || isPartOfMultiSelection, adjustScrolling: isSelected || isFirstMultiSelectedBlock( clientId ),