Skip to content
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

Merged
merged 10 commits into from
Jul 15, 2024

Conversation

akasunil
Copy link
Member

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

  • Add a Tag cloud block.
  • In the settings panel, in the options "smallest size" and "largest size", change the unit.

@akasunil akasunil requested a review from ajitbohra as a code owner February 16, 2024 11:41
Copy link

github-actions bot commented Feb 16, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

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>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@carolinan carolinan added [Type] Bug An existing feature does not function as intended [Block] Tag Cloud Affects the Tag Cloud Block labels Feb 16, 2024
@akasunil akasunil marked this pull request as draft February 27, 2024 07:18
@akasunil akasunil marked this pull request as ready for review February 29, 2024 08:18
@akasunil
Copy link
Member Author

@Mamaduka can you please review this PR ?

@Mamaduka Mamaduka requested a review from carolinan March 17, 2024 17:14
@carolinan
Copy link
Contributor

@sunil25393 Hi. Did you explore if it was possible to make the pt unit available?

@akasunil
Copy link
Member Author

@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 getValidParsedQuantityAndUnit to determine whether the unit is available or not. If the unit is not made available by the theme. Then we may select the first unit from the list as the default unit.

Please let me know if you have any alternative approaches.

@akasunil akasunil self-assigned this Jun 25, 2024
@carolinan
Copy link
Contributor

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.

@akasunil
Copy link
Member Author

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' ],
Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely remember having a discussion about font size unit block support with @t-hamano but I can't find that issue or PR now.

BTW unit support is broken in block.json #47519

Copy link
Contributor

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' ],
} );

Copy link
Member Author

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?

Copy link
Contributor

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.

@akasunil
Copy link
Member Author

akasunil commented Jul 3, 2024

@carolinan can you please review this PR and let me know your thoughts.

@carolinan
Copy link
Contributor

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.

@jasmussen
Copy link
Contributor

Thanks for the ping, that lets me clarify this part:

But one single recommedation I'd make is to adopt the unit-selector input field. That would both let us remove the (pt) from the label, and pick other units. Is that feasible?

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:

Screenshot 2024-07-03 at 10 26 39

I don't personally mind if someone wants to use the pt unit for font sizes.

@ntsekouras
Copy link
Contributor

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.

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 pt. So if we changed the default unit, it would affect all previous instances of that block..

@akasunil
Copy link
Member Author

akasunil commented Jul 6, 2024

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.

@carolinan
Copy link
Contributor

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.

Copy link
Contributor

@ntsekouras ntsekouras left a 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!

@ntsekouras ntsekouras merged commit 3f34e00 into WordPress:trunk Jul 15, 2024
60 checks passed
@github-actions github-actions bot added this to the Gutenberg 18.9 milestone Jul 15, 2024
@carolinan
Copy link
Contributor

carolinan commented Jul 15, 2024

Nik was faster :)
Thank you for working on this @akasunil. I'm glad the initial calculations were not needed.
This works well both when the theme sets spacing units with theme.json, and when it does not.

@akasunil akasunil deleted the fix-issue-58885 branch July 15, 2024 08:25
@akasunil
Copy link
Member Author

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.

scruffian pushed a commit that referenced this pull request Jul 15, 2024
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>
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Jul 18, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Tag Cloud Affects the Tag Cloud Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tag cloud: if you change size unit you can't reselect PT
5 participants