Skip to content
Closed
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
18 changes: 13 additions & 5 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import BlockTransformationsMenu from './block-transformations-menu';
import { useBlockVariationTransforms } from './block-variation-transformations';
import BlockStylesMenu from './block-styles-menu';
import PatternTransformationsMenu from './pattern-transformations-menu';
import useBlockDisplayTitle from '../block-title/use-block-display-title';
import { unlock } from '../../lock-unlock';

function BlockSwitcherDropdownMenuContents( {
Expand Down Expand Up @@ -200,6 +199,7 @@ export const BlockSwitcher = ( { clientIds } ) => {
isTemplate,
isDisabled,
isSectionInSelection,
blockTitle,
} = useSelect(
( select ) => {
const {
Expand All @@ -223,6 +223,7 @@ export const BlockSwitcher = ( { clientIds } ) => {

let _icon;
let _hasTemplateLock;
let _blockTitle;
if ( _isSingleBlockSelected ) {
const match = getActiveBlockVariation(
firstBlockName,
Expand All @@ -232,6 +233,15 @@ export const BlockSwitcher = ( { clientIds } ) => {
_icon = match?.icon || blockType.icon;
_hasTemplateLock =
getTemplateLock( clientIds[ 0 ] ) === 'contentOnly';

// For BlockSwitcher, we only show the block type or variation name
// We don't need custom labels (metadata.name) - those are only for list view
_blockTitle = match?.title || blockType.title;

// Truncate if needed (max 35 chars)
if ( _blockTitle && _blockTitle.length > 35 ) {
_blockTitle = _blockTitle.slice( 0, 34 ) + '…';
}
Comment on lines +237 to +244
Copy link
Member

@Mamaduka Mamaduka Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic doesn't account for all cases, like dynamic block titles.

Screenshot

CleanShot 2025-10-23 at 18 57 51

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this isn't the right change. I'd like it to be a fix within useBlockDisplayTitle. The architecture of needing two subscriptions that get retriggered on every keystroke to get a static title is bothersome to me 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I tried to optimize it in the past (#58250), so I'm happy to review changes when they're ready.

} else {
const isSelectionOfSameType =
new Set( _blocks.map( ( { name } ) => name ) ).size === 1;
Expand All @@ -241,6 +251,7 @@ export const BlockSwitcher = ( { clientIds } ) => {
// When selection consists of blocks of multiple types, display an
// appropriate icon to communicate the non-uniformity.
_icon = isSelectionOfSameType ? blockType.icon : copy;
_blockTitle = null; // Not used for multiple blocks
}

const _isSectionInSelection = clientIds.some( ( id ) =>
Expand All @@ -260,14 +271,11 @@ export const BlockSwitcher = ( { clientIds } ) => {
hasContentOnlyLocking: _hasTemplateLock,
isDisabled: editingMode !== 'default',
isSectionInSelection: _isSectionInSelection,
blockTitle: _blockTitle,
};
},
[ clientIds ]
);
const blockTitle = useBlockDisplayTitle( {
clientId: clientIds?.[ 0 ],
maximumLength: 35,
} );
const showIconLabels = useSelect(
( select ) =>
select( preferencesStore ).get( 'core', 'showIconLabels' ),
Expand Down
Loading