Skip to content

Commit

Permalink
Limit Copy/Paste Styles menu item to only those blocks that have eith…
Browse files Browse the repository at this point in the history
…er 'color' or 'typography' supports (#51503)
  • Loading branch information
pbking authored Jun 15, 2023
1 parent 45e47b1 commit e36186c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
10 changes: 10 additions & 0 deletions packages/block-editor/src/components/block-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ export default function BlockActions( {

const blocks = getBlocksByClientId( clientIds );
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );

const canCopyStyles = blocks.every( ( block ) => {
return (
!! block &&
( hasBlockSupport( block.name, 'color' ) ||
hasBlockSupport( block.name, 'typography' ) )
);
} );

const canDuplicate = blocks.every( ( block ) => {
return (
!! block &&
Expand Down Expand Up @@ -64,6 +73,7 @@ export default function BlockActions( {
const pasteStyles = usePasteStyles();

return children( {
canCopyStyles,
canDuplicate,
canInsertDefaultBlock,
canMove,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export function BlockSettingsDropdown( {
__experimentalUpdateSelection={ ! __experimentalSelectBlock }
>
{ ( {
canCopyStyles,
canDuplicate,
canInsertDefaultBlock,
canMove,
Expand Down Expand Up @@ -330,16 +331,18 @@ export function BlockSettingsDropdown( {
</>
) }
</MenuGroup>
<MenuGroup>
<CopyMenuItem
blocks={ blocks }
onCopy={ onCopy }
label={ __( 'Copy styles' ) }
/>
<MenuItem onClick={ onPasteStyles }>
{ __( 'Paste styles' ) }
</MenuItem>
</MenuGroup>
{ canCopyStyles && (
<MenuGroup>
<CopyMenuItem
blocks={ blocks }
onCopy={ onCopy }
label={ __( 'Copy styles' ) }
/>
<MenuItem onClick={ onPasteStyles }>
{ __( 'Paste styles' ) }
</MenuItem>
</MenuGroup>
) }
<BlockSettingsMenuControls.Slot
fillProps={ {
onClose,
Expand Down

1 comment on commit e36186c

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in e36186c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5282736906
📝 Reported issues:

Please sign in to comment.