-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RichText: Add the RichText.Content component to be used in conjunction with RichText #6274
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with value
prop in #5380 . One advantage is that it doesn't mislead one to think there's a wrapper element applied, which at a glance it might appear there is.
blocks/rich-text/README.md
Outdated
@@ -95,6 +100,12 @@ wp.blocks.registerBlockType( /* ... */, { | |||
} | |||
} ); | |||
}, | |||
|
|||
save: function() { | |||
return wp.element.createElement( 'h2, {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing single quote after h2
.
@@ -876,7 +876,7 @@ RichText.defaultProps = { | |||
format: 'element', | |||
}; | |||
|
|||
export default compose( [ | |||
const RichTextContainer = compose( [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just reassign RichText
here? RichText = compose( [ ] )( RichText );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not possible because we use the inner RichText in unit tests.
docs/blocks-editable.md
Outdated
@@ -112,4 +118,4 @@ The `RichText` component can be considered as a super-powered `textarea` element | |||
|
|||
Implementing this behavior as a component enables you as the block implementer to be much more granular about editable fields. Your block may not need `RichText` at all, or it may need many independent `RichText` elements, each operating on a subset of the overall block state. | |||
|
|||
Because `RichText` allows for nested nodes, you'll most often use it in conjunction with the `children` attribute source when extracting the value from saved content. | |||
Because `RichText` allows for nested nodes, you'll most often use it in conjunction with the `children` attribute source when extracting the value from saved content. You'll also most likely use `RichText.Content` in the `save` function to output RichText values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"most likely" ? Uncertainty here would be confusing to a developer, particularly without explanation of if/when it should be applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this is because the quote
values are left alone? Not sure. Will be simpler after #6054.
What do you mean with this? I lean towards the
|
I was thinking:
This way it matches |
Sounds great! |
bb3f651
to
9865287
Compare
Updated, I think it's nicer this way where we mimic the same API as RichText. I was thinking of introducing a |
When would it be logged? There's a legitimate concern here that this is less convenient for developers in some way, as the previous approach was "simpler", albeit not always consistent with the new format options. |
I was thinking to always log it once when you load Gutenberg (RichText file) for some versions. I wonder how we can communicate about this better? |
@@ -194,7 +194,7 @@ export const settings = { | |||
|
|||
<figure className={ align ? `align${ align }` : null }> | |||
{ src && <video controls src={ src } /> } | |||
{ caption && caption.length > 0 && <figcaption>{ caption }</figcaption> } | |||
{ caption && caption.length > 0 && <RichText.Content tagName="figcaption" value={ caption } /> } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering, but would it be good to incorporate the empty check in RichText.Content
? This seems to be a common pattern. Even if the block registration has no such check, I don't think there are any cases where it makes sense to render an empty element in save
context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on the fence here because I wonder if it's possible sometimes to render the container tag without its content ( like an empty list item or something). Let's keep it as is for now.
It seems we all agree we need to move away form storing the React objects, so this will be beneficial in any case, unless you'd prefer to handle this in the I'm also not sure if I agree that this is more complicated... It's more verbose, yes, but it's simple in the sense that it's very similar to what you use for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. +1 from me.
After a second thought, I'm going to merge this as is. The warning should be introduced later when we settle on the format we want as a replacement for the default "element" format. That way we will ask people to only update their code once and not twice (Add |
…n with RichText (WordPress#6274) * RichText: Add the RichText.Content component to be used in conjunction with RichText * Support tagName and extra props in RichText.Content * Use RichText.Content in quotes as well * Fix unit tests
related #6034
This PR adds a
RichText.Content
to clarify the usage of RichText values in thesave
function. Block authors don't need to know that the value is a react element and can be embedded. They just declare that it's a richtext value with a given format:Questions
Right now the API of RichText.Content doesn't match directly the API of RichText so we end up with something like this:
I was thinking that we could align both which means:
tagName
prop toRichText.Content
value
prop instead ofchildren
multiple
(if multiple is not false, don't render any parent tag name)Thoughts?
Notes
One of the ideas behind this component is that it will allow us to switch the default format at some point (tree or string) with a clear deprecation strategy.