-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
PostTitle: be able to set post title via own prop #20609
Conversation
Size Change: -66 B (0%) Total Size: 865 kB
ℹ️ View Unchanged
|
It implements a hacky solution to propagate the template title to the <PostTitle /> component, since it isn't possible to do it in thr current implementation of the component. I've created a PR, but in the meanwhile we can take this patch in order to give a quick solution. We can iterate later once the code PR is ship? WordPress/gutenberg#20609
@@ -141,7 +141,7 @@ const applyWithSelect = withSelect( ( select ) => { | |||
|
|||
return { | |||
isCleanNewPost: isCleanNewPost(), | |||
title: getEditedPostAttribute( 'title' ), | |||
title: getEditedPostAttribute( 'title' ) || ownTitle, |
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.
With this priority, you will never be able to use the override on a page that already has a title assigned and getEditedPostAttribute
will be returning value. It will only work on title-less page which I don't think is the goal here
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 thought title
will try to get the value from getEditedPostAttribute( 'title' )
as first option. If it isn't defined then it will try to apply the second part which is ownTitle
. Testing again.
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.
It will only work on title-less page which I don't think is the goal here
Actually it's the desired goal here
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.
do you think that the explicit value should be stronger than site post?
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 think it depends on what you are trying to achieve.
Is the custom title provided as a prop conceptually a "placeholder" value or not.
In my head the data flow model suggests that if you provide a prop such as title
then you should expect that title to be reflected in the rendered component. To have a side effect suddenly change the title to something else entirely could feel very odd. I've provided a title
so show that title.
Alternatively if you call the prop fallbackTitle
then it might be legitimate to have the title rendered unless the post attribute title isn't available.
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.
What do you think about __experimentalFallbackTitle
?
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 way you can really only use the component override in an iframe (where there will never be a post title) but that's not how normal usages would look like. If we make it title
and change the order in the condition, I think that would be a much more useful API for others too. That way you will be able to render strings styled as titles anywhere. Up to you to make the decision but I find it strange in the current form
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.
yeah, I think makes sense what you do suggest. Addressed here.
* spt: set template using post-title component It implements a hacky solution to propagate the template title to the <PostTitle /> component, since it isn't possible to do it in thr current implementation of the component. I've created a PR, but in the meanwhile we can take this patch in order to give a quick solution. We can iterate later once the code PR is ship? WordPress/gutenberg#20609 * spt: refact adding setTemplateTitle * spt: apply delay for the first-rendering cycle * spt: remove core/heading teplate title from blocks * spt: add padding top to the template title * spt: add missing template title classname * Update apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/block-iframe-preview.js Improve jsdoc. Props to @getdave :-) Co-Authored-By: Dave Smith <[email protected]> * Update apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/block-iframe-preview.js Improve jsdoc. Props to @getdave Co-Authored-By: Dave Smith <[email protected]> * Update apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/styles/starter-page-templates-editor.scss Set the CSS class name more targetted to the SPT scope. Co-Authored-By: Dave Smith <[email protected]> * spt: reduce redice hook effect requeriments * spt: remove setTimeout hack * spt: always render preview content * spt: remove unneeded id attribute * spt: removes CSS hack * spt: improve doc Co-authored-by: Dave Smith <[email protected]>
I'm not sure I follow this. In the context of wp.data.dispatch( 'core/editor' ).editPost( { title: 'My explicit title' } ); It doesn't seem consistent to me in how editor components are intended to operate that we would need to bypass the post entity for showing a title. |
We want to make a preview of the post content, for instance. Take a look at the following picture: There, there isn't a blog post at all. It's just a handful of blocks. But I'd like to put the post title among the page blocks, as part of the preview, too.
There isn't a blog post to target.
Yeah, that is what I thought initially. It's fair enough. |
What behaviors are you trying to reuse? Because all of the components in editor are pretty targeted at use with interoperating with a post, so they don't make much sense to use outside that context. But if there are specific behaviors of the component you'd like to leverage, maybe there's opportunity to extract a lower-level reusable component. Also worth noting, in case it's unclear, that by "post", I consider to include pages as well, since a page is simply one of the possible types of a post. I believe as part of the full-site editing effort, there may also be some work to extract a "Post Title" block (#18461), though even this I would still expect to interact with a post entity. |
Yeah, I think it fits very well with our case.
Yeah, got it. I'm aware of this as well :-D
Taking a look at this implementation. |
Description
This PR proposes to be able to set the title prop of the
<PostTitle />
explicitly., giving priority to the post title attribute, trying to guarantee it won't affect the current and natural behavior of the component.Particularly, we are working on some stuff related to the page preview, and we'd like to use
<PostTitle />
component on this context, where among many particularities, the site post doesn't exist. With the current implementation, is not possible to set arbitrarily the title.How has this been tested?
<PostTitle />
as property. Just for testing purposes, I've edited the component with something like this:The static title value should be shown only if the post doesn't have defined a title. Once the post gets its title value, it should be shown properly.Checklist: