Introduce CustomElement interoperability for block types #17649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Addressing #17360, this is a port from #2791, migrating that PR to work within the current APIs and making a few adjustments.
Types of changes
CustomElement
component, which accepts atagName
,attributes
and variable other props. Internally it creates a custom element oftagName
, and adds theattributes
as HTML attributes, and all other props as HTML properties.edit
property is a custom element tag name, and if so use the above component to render it instead of directly interpretingedit
as a component.edit
when registering a block type.Considerations
CustomElement
component itself is very generic and technically not limited to the block editor. I'd like for us to consider whether we want to add it to the@wordpress/element
package. I didn't want to do that without discussing first, but I think this being a workaround for something essential that React does not allow out of the box gives us food for thought whether we should include it in that package.isCustomElement()
function, which goes together with theCustomElement
component. Right now the function is even redeclared (we should definitely address that one way or another) because I wasn't sure where to put it (@wordpress/element
would work) so that all areas where it's needed could access it.@wordpress/custom-element
.save
. That would clarify the intent that you can easily use a custom element even for both variantsedit
andsave
(without having to do that of course). Today, an easy way the custom element could check whether it is in edit mode or not would be checking if asetAttributes
property is present or not.Checklist: