-
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
Fix default unit issue for tag cloud block #59122
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@Mamaduka can you please review this PR ? |
@sunil25393 Hi. Did you explore if it was possible to make the pt unit available? |
@carolinan Here, the PT unit is utilized as the default font size value, and available units are obtained from the spacing.units setting, which can be changed by the theme. As you can see, the twentyTwentyFour theme's spacing units do not include the PT unit. So, even if I add PT units to this list, the problem will persist. To overcome this problem, I have used Please let me know if you have any alternative approaches. |
Spacing units are separate from font size units. If spacing units affects typography then that is a separate bug that needs to be reported and solved separately from this issue and pr. |
If we remove the use of spacing.units ( as you mentioned spacing units should not be used for font sizes ), then i guess we can include PT unit in default units. Also, we don't have global styles setting for font size units like spacing.units, so we just have to use an array of hard coded units like here. i'll update my PR accordingly. |
const units = useCustomUnits( { | ||
availableUnits: availableUnits || [ '%', 'px', 'em', 'rem' ], | ||
availableUnits: [ 'px', 'em', 'rem', 'vw', 'vh', 'pt' ], |
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.
Added same units as we use for font size picker including PT unit. And removed use of spacing units setting for font sizes.
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 feels to me that we should always honor the spacing units and we shouldn't remove this. Having said that, since the tag cloud has this nuance with the previous default value, maybe we should just append the pt
to the availableUnits
in either case (spacing.units or defaults). What do you think?
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 is not logical to me that spacing units are used as the font size unit and I would like to understand why they were used this way?
I don't think pt is used for spacing.
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.
That's a good question! Do we have a different theme.json setting for font size units? I searched a bit and I think not.. We should probably use the same values we use for setting font sizes in typography panel (size).
My point is, if we have such a setting and we were using the wrong one, we should honor it. I'll cc @MaggieCabrera if she can provide some feedback.
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.
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 is not logical to me that spacing units are used as the font size unit
I completely agree with this point, but given that theme.json doesn't support font size units, I think we need to respect spacing.units
for now to maintain backward compatibility.
How about keeping the current specs but adding the pt
unit?
// The `pt` unit is used as the default value and is therefore
// always considered an available unit.
const units = useCustomUnits( {
availableUnits: availableUnits
? [ ...availableUnits, 'pt' ]
: [ '%', 'px', 'em', 'rem', 'pt' ],
} );
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.
Thank you @t-hamano, Let me know If we all are agree with the above proposed solution, ill update the PR
Also, Shouldn't we consider having a unit setting for font size in theme.json
?
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 believe this approach is the best one to maintain backward compatibility and users to reselect the pt
unit.
allow
Shouldn't we consider having a unit setting for font size in "theme.json"?
Of course, this is a feature improvement that should be considered in a separate PR.
@carolinan can you please review this PR and let me know your thoughts. |
Let's ping @amustaque97 and @ntsekouras to ask if there are any important reasons to why the spacing units was used for this font size control, that I may have missed. And @jasmussen who I believe requested that the pt size was removed. Original PR: #37311. |
Thanks for the ping, that lets me clarify this part:
I meant that allowing the unit selector would allow us to change the label of the previous implementation to omit the hardcoded mention of PT: I don't personally mind if someone wants to use the pt unit for font sizes. |
It's been a while since that PR, but I think it's because in the block's render function(dynamic) we use wp_tag_cloud where the default unit is |
Hello, @ntsekouras I appreciate your response. Actually, the default unit is not being changed. The array of units used in the front size picker have taken the role of the spacing units settings, and the PT unit has been included in that array. PT unit support will still be available in tag cloud block. |
Yes the default unit should still be PT, what we are trying to solve here is that right now, on trunk, you can't switch back to PT if you select a different unit. On trunk PT is not available in the control. |
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.
Looks good, thank you!
Nik was faster :) |
Thanks @carolinan and @ntsekouras Just wondering, though: wouldn't it be confusing if a user removed a PT unit from theme.json yet it continued to show up on the tag cloud block? The initial calculations were to prevent this by setting the PT unit's default value to the first accessible unit's value. |
Co-authored-by: akasunil <sunil25393@git.wordpress.org> Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: akasunil <sunil25393@git.wordpress.org> Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org>
Fixed #58885
What?
Tag cloud block default size is set in PT unit, but when PT unit is not available, it vanish on unit change.
Why?
Converting default value into first available unit.
also modified
parseQuantityAndUnitFromRawValue()
to return default unit value when match not found. Before it was returning undefined even when match isn't found.Testing Instructions