-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
What problem does this address?
Hello folks 👋🏼 we have a custom block that should always be on the page, should not be moved, and should not be removed. To accomplish this, supports.removal = false
and supports.multiple = false
in block.json
. As well, the block pattern that provides the custom block to all posts restricts removing and moving the block.
The problem is that you are still able to copy and paste the block. This leads to a strange user experience. Since multiple is false, a message is given to the user after they paste the block that only 1 of the block is supported. However, because removal isn’t supported, the user cannot delete the pasted block. Only Undo seems to work.
What is your proposed solution?
It could be helpful for this issue if the combination of supports.multiple = false
and supports.removal = false
meant Copy and Paste of the block is not supported in the editor.
Right now, with those settings, copy and paste is still enabled and available via menu, and this seems expected when viewing the source.
gutenberg/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js
Lines 295 to 298 in b0dbcf8
<CopyMenuItem | |
blocks={ blocks } | |
onCopy={ onCopy } | |
/> |
gutenberg/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js
Lines 299 to 310 in b0dbcf8
{ canDuplicate && ( | |
<MenuItem | |
onClick={ pipe( | |
onClose, | |
onDuplicate, | |
updateSelectionAfterDuplicate | |
) } | |
shortcut={ shortcuts.duplicate } | |
> | |
{ __( 'Duplicate' ) } | |
</MenuItem> | |
) } |
Notice canDuplicate
is only influencing the Duplicate button and the CopyMenuItem
exists without condition. I thought maybe a conditional existed earlier, but I checked onCopy
and that doesn’t seem to be the case either.
gutenberg/packages/block-editor/src/components/block-actions/index.js
Lines 134 to 142 in b0dbcf8
onCopy() { | |
const selectedBlockClientIds = blocks.map( | |
( { clientId } ) => clientId | |
); | |
if ( blocks.length === 1 ) { | |
flashBlock( selectedBlockClientIds[ 0 ] ); | |
} | |
notifyCopy( 'copy', selectedBlockClientIds ); | |
}, |
So that’s what brings me here today. I’m curious if it would be as simple as adding a check on the copy button that is influenced by the supports.multiple
in block.json
. Similar to how it seems to work for Duplicate support.
Anyways, thanks for your time and I look forward to working together on this issue 😁