Block API: Add new bindAttribute helper for editor inputs#7352
Block API: Add new bindAttribute helper for editor inputs#7352
Conversation
|
Thanks for the exploration, @aduth. The As a block owner, I would expect this to work on all Gutenberg-supplied input components, not only After looking at the core blocks, I am surprised how often we can't use Overall |
|
Yes, the There's a bit of context in the original comment to why this was only introduced for RichText currently, due to challenges around Slot/Fill and inheriting context. I'll close this for now as an interesting exploration that could be picked up later if desired. |
Related: #5739
This pull request seeks to explore a developer experience optimization for implementations of blocks, reducing the effort necessary to support value changing of an attribute via a new optional
bindAttributeprop for use in editor input components.Before:
After:
This is intended to be very similar to React's now-deprecated
LinkedStateMixin, a pattern for two-way data binding. While it sacrifices explicitness, it does so in a way intentionally for promoting a simplified developer experience for block implementers, in a consistent fashion to the automatic handling ofRichTextfocus andisSelectedconditional rendering.Implementation notes:
Attribute binding is achieved with a new
withBindAttributehigher-order component, which can be applied to any editor input component to optionally accept thebindAttributeprop as an alternative to thevalueandonChangepairing.Currently, this is only implemented for
RichText. It has proven to be difficult to implement for other components becausecontextis lost in Slot/Fill for non-bubblesVirtuallyslots (including toolbars and inspector controls). This will need to be addressed separately as a general issue, either updating all existing slots to usebubblesVirtuallyor a way for context to be preserved in non-virtual-bubbling slots rendering.Testing instructions:
Verify that there are no regressions in the display and editing of a paragraph block's value.