-
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
Post Title: Add support for text decoration #38986
Conversation
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) { | ||
$title = sprintf( '<a href="%1$s" target="%2$s" rel="%3$s">%4$s</a>', get_the_permalink( $post_ID ), esc_attr( $attributes['linkTarget'] ), esc_attr( $attributes['rel'] ), $title ); | ||
return sprintf( | ||
'<%1$s><a href="%2$s" target="%3$s" rel="%4$s" %5$s>%6$s</a></%1$s>', |
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.
Where did $tag_name
come from? Why do we now have a wrapping element?
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.
Previously this was output to a $title
variable. $title
was then wrapped in a wrapping element after the if statement.
This change simply returns the whole markup rather than creating a variable, which I thought was easier to read than having multiple if statements.
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 appreciate this might seem like a nit pick, but in order to keep this PR focused I really think we should go back to the previous setup whereby we had a single return
statement.
Why?
Having two return
statements means the HTML output is effectively generated in x2 places thus increasingly the complexity of reasoning around the code. It also doubles the surface area for the introduction of XSS bugs (as evidenced by the original omission of the esc_*
functions in this PR).
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.
Appreciate your work here and patience in responding to my queries.
Nonetheless, I'm still a bit confused here. Could you help me to understand a few things?
I just want to make sure I fully understand the change and how it's being applied and what implications there are in terms of backwards compatibility.
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) { | ||
$title = sprintf( '<a href="%1$s" target="%2$s" rel="%3$s">%4$s</a>', get_the_permalink( $post_ID ), esc_attr( $attributes['linkTarget'] ), esc_attr( $attributes['rel'] ), $title ); | ||
return sprintf( | ||
'<%1$s><a href="%2$s" target="%3$s" rel="%4$s" %5$s>%6$s</a></%1$s>', |
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 appreciate this might seem like a nit pick, but in order to keep this PR focused I really think we should go back to the previous setup whereby we had a single return
statement.
Why?
Having two return
statements means the HTML output is effectively generated in x2 places thus increasingly the complexity of reasoning around the code. It also doubles the surface area for the introduction of XSS bugs (as evidenced by the original omission of the esc_*
functions in this PR).
get_the_permalink( $post_ID ), | ||
esc_attr( $attributes['linkTarget'] ), | ||
esc_attr( $attributes['rel'] ), | ||
$wrapper_attributes, |
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.
We're now applying the wrapper_attributes
to the <a>
as opposed to the wrapping tag. What are the impacts on this on Theme styling and potential regressions?
The aim of the PR is to be able to control the text decoration of the post title block. The block markup is dependent on whether or not the post-title has the isLink attribute set. With This isn't easy to do, since the block supports just return a long string of styles and classes, so you can't apply some of them to some elements and some to others, so instead I am just applying all of the rules to the We could avoid the double return by assigning the link to a variable and and outputting the wrapper attributes based on the isLink condition, but I think this would probably be harder to understand. Alternatively we could apply the wrapper attributes to both the wrapper element and the link. There are a few other options we could explore if we want to more granular control, but they would take significant work: Block supports have the concept of an Another option would be to create more granular hooks for every block support mechanism, which would allow us to control which tags they are applied to. This would require a significant rework of how block supports work, see #38167. Another option would be to always output the |
I just want to say it is just a matter of time before the Post Title block becomes the go to when a user wants to add a page/post title to their layout. As in this issue: #27093 It would be natural to have all the "regular" settings as one have in a Paragraph block also in the Post Title block. |
@scruffian Thanks for the context. It helps a lot. I'm going to pull this down and take a more detailed look later today. |
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 noticed during testing that the text decoration UI isn't showing up in the editor
Screen.Capture.on.2022-03-01.at.11-59-44.mov
I think that's ok for now. The aim of this PR is to get text decoration working via theme.json. We can add the UI in a later PR. |
Ok that's fine 👍 Would you mind re-visiting the testing instructions in order that we can validate the PR a little? Thanks! |
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.
Some things I noticed on first checkout and test.
Editor does not reflect text decoration when it's a link
Screen.Capture.on.2022-03-02.at.14-19-17.mp4
Classname placement inconsistency on front of site
When switching between making the block a link or not, the markup varies. The main issue I see is that the .wp-block-post-title
moves from the <h2>
to the <a>
.
I imagine this is likely to cause regressions and seems heavy handed considering what we actually want to achieve is just moving the style="text-decoration:line-through;"
to the <a>
.
I think we should investigate using __experimentalSelector
to see if we can better target the <a>
element.
I found that this support was already added by #42328. Can this PR be closed? |
Closed by #42328 |
Description
We removed support for text decoration from the Post Title block in #34064, though I'm not quite sure why. This adds back that support, but it makes a few changes to ensure that it is applied to the link, not to the wrapper, if there is a link.
We might want to get #31768 shipped as part of this change too?
Testing Instructions
Open a page template that contains a Post Title
Edit the block and confirm that you can add a "strikethrough" text decoration
Also confirm that the setting can be "none" as per Automattic/themes#5573
Screenshots
Types of changes
New feature (non-breaking change which adds functionality)
Checklist:
*.native.js
files for terms that need renaming or removal).