Skip to content

Commit

Permalink
Display block anchor in List View when set. (#31992)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtias authored May 20, 2021
1 parent 635ffee commit 96134ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ function BlockNavigationBlockSelectButton(
<Indentation level={ level } />
<BlockIcon icon={ blockInformation?.icon } showColors />
<BlockTitle clientId={ clientId } />
{ blockInformation?.anchor && (
<span className="block-editor-block-navigation-block-select-button__anchor">
{ blockInformation.anchor }
</span>
) }
{ isSelected && (
<VisuallyHidden>
{ __( '(selected block)' ) }
Expand Down
15 changes: 15 additions & 0 deletions packages/block-editor/src/components/block-navigation/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,21 @@
color: $white;
}
}

.block-editor-block-navigation-block-select-button__anchor {
background: rgba($black, 0.1);
border-radius: $radius-block-ui;
display: inline-block;
padding: 2px 6px;
margin: 0 $grid-unit-10;
max-width: 120px;
overflow: hidden;
text-overflow: ellipsis;
}

&.is-selected .block-editor-block-navigation-block-select-button__anchor {
background: rgba($black, 0.3);
}
}

.block-editor-block-navigation-block-slot__description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ export default function useBlockDisplayInformation( clientId ) {
const blockName = getBlockName( clientId );
const blockType = getBlockType( blockName );
if ( ! blockType ) return null;
const attributes = getBlockAttributes( clientId );
const match = getActiveBlockVariation( blockName, attributes );
const blockTypeInfo = {
title: blockType.title,
icon: blockType.icon,
description: blockType.description,
anchor: attributes?.anchor,
};
const attributes = getBlockAttributes( clientId );
const match = getActiveBlockVariation( blockName, attributes );
if ( ! match ) return blockTypeInfo;

return {
title: match.title || blockType.title,
icon: match.icon || blockType.icon,
Expand Down

0 comments on commit 96134ef

Please sign in to comment.