Since apiVersion 2, customization of core blocks is more difficult #34104
Labels
Backwards Compatibility
Issues or PRs that impact backwards compatability
[Feature] Extensibility
The ability to extend blocks or the editing experience
Needs Technical Feedback
Needs testing from a developer perspective.
[Package] Block editor
/packages/block-editor
[Type] Enhancement
A suggestion for improvement.
Description
Since apiVersion 2, Blocks are no longer automatically wrapped in a
BlockListBlock
.gutenberg/packages/block-editor/src/components/block-list/block.js
Line 162 in 20d9c54
useBlockProps
in order to render theblockProps
gutenberg/packages/block-editor/src/components/block-list/use-block-props/index.js
Line 63 in 20d9c54
Step-by-step reproduction instructions
Lets say I wanted to add a title element to a core gallery:
Screenshots, screen recording, code snippet
in apiVersion 1, this would have resulted in the following markup, note the block props on the outermost element:
Which also results in appropriate placement of the block controls above the title field:
Also, note the in-between inserter popover working as expected:
in apiVersion 2, the
blockProps
are moved inside the wrapper element:Note the bad placement of the block controls before the gallery component rather than wrapper element
Also, the in-between inserter fails to function due to the incorrectly positioneded
blockProps
propsI can essentially solve this issue in a very hacky way by utilizing
useBlockProps
and applying to the wrapper div, but this results in duplicated id's and classnames etc because thecore/gallery
also implementsuseBlockProps
Adding a filter allowing developers to modify
useBlockProps
would be useful, but there would need to be some way to determine ifuseBlockProps
was being called in the block edit function context, or theBlockEdit
filter context, so as not to filter the props in both situations.It occurred to me that another possible solution might be to create a Slot similar to inspector controls allowing developers to inject additional fields into core blocks.
Also if there is another solution, that I have not thought of or mentioned here, I'd love to know what peoples thought son that are.
Environment info
Related - #33953
Pre-checks
The text was updated successfully, but these errors were encountered: