Block API: Add new bindAttribute helper for editor inputs #7352
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.
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
bindAttribute
prop 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 ofRichText
focus andisSelected
conditional rendering.Implementation notes:
Attribute binding is achieved with a new
withBindAttribute
higher-order component, which can be applied to any editor input component to optionally accept thebindAttribute
prop as an alternative to thevalue
andonChange
pairing.Currently, this is only implemented for
RichText
. It has proven to be difficult to implement for other components becausecontext
is lost in Slot/Fill for non-bubblesVirtually
slots (including toolbars and inspector controls). This will need to be addressed separately as a general issue, either updating all existing slots to usebubblesVirtually
or 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.