-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix selection of font size presets if presets have the same size value
#71703
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 selection of font size presets if presets have the same size value
#71703
Conversation
…ling back to one, also design update
… M - L - XL - XXL, where having the same size wasn't possible to select either
|
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. |
This comment was marked as outdated.
This comment was marked as outdated.
t-hamano
left a comment
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.
Thanks for the PR!
Like many other components, I think that which items are selected or not should be determined by a single source.
Even if a user sets custom fluid values, the original
sizevalue is stored and used as a selection reference.
This is the fundamental problem we need to address. This may be difficult, but can we generate a unique size value from fluid.min and fluid.max? Or, when passing a prop to the FontSizePicker component, can we pass the actual clamp value as the size value instead of 16px?
Together with items that break into two lines, this would have looked confusing, as information for different items have showed differently.
If this is a real problem, it should be fixed in the CustomSelectControl component itself, rather than overriding the CustomSelectControl behavior. Perhaps we can discuss the design in a separate issue or PR.
packages/components/src/font-size-picker/font-size-picker-select.tsx
Outdated
Show resolved
Hide resolved
|
Thank you for your feedback @t-hamano!
I don't think generating a unique size will solve the problem. It would make most sense to me to have the entire
Would this be a blocker now for this PR? |
I don't think this is a blocker, but I don't understand why a special layout is needed just for the font size picker 🤔 |
Let's call it "path of least resistance" 😅 Let me try to figure out a better way in the |
Agreed. Also, there are plans for a new and improved CustomSelectControl which will allow for easier layout customization like this at the instance-level, so there's also an option to wait until that's ready. |
Is there already an issue for improving the CustomSelectControl? |
Sorry, hard to find 😅 #55023 |
|
@mirka is there a timeline on that being implemented? I know that is a hard ask but I am wondering if that is going to be a blocker to getting this in or if this could be something worked around within this PR to not require changes to a global component. That might be asking a lot and the other option is to get some timing on this with the other issue if that is possible. What I see in review is an issue started in 2023, with quite a bit of work going on lately (which is great), does this mean it is going to land in the next few versions or hope to? |
|
I'm not in a position to say about the timeline, but I don't think it necessarily has to be a blocker for this PR. If we only need to wrap the |
I have now reduced the CSS to that one line changing the I've tried to get the remaining checks passing but for some reason it always gets stuck on this: But the component is imported as an external dependency a few lines above. Or am I doing something else wrong here? @mirka @t-hamano @Mamaduka |
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.
Thanks a lot for tackling this tricky problem!! 🙏🏻
Sorry if a lot of my comments are premature - I know you're working on the internals.
I think things are on the right track with the valueMode as folks have suggested, I was just having trouble testing the functionality in both block and global styles.
From what I can gather we're going to refer to selectedSlug and then set valueMode to "slug" if there is one?
In my opinion, unit tests would greatly help reason about the logic here (and catch bugs!). Also updating the storybook examples to cover these cases. If this is to get into 6.9 then I think both are required, even as follow ups to this PR.
But I understand things are still in motion so take what I've said with as much salt as you need right now 😄
Here' an example of some presets I was testing:
theme.json typography settings
"typography": {
"defaultFontSizes": false,
"fluid": true,
"fontSizes": [
{
"name": "Tiny Test",
"slug": "tiny",
"size": "12px"
},
{
"name": "Small Test",
"slug": "small",
"size": "12px"
},
{
"name": "Base Test",
"slug": "base",
"size": "16px"
},
{
"name": "Medium Test",
"slug": "medium",
"size": "18px"
},
{
"name": "Large Test",
"slug": "large",
"size": "20px"
},
{
"name": "Extra Large Test",
"slug": "extra-large",
"size": "24px"
},
{
"name": "Huge Test",
"slug": "huge",
"size": "32px",
"fluid": {
"min": "16px",
"max": "32px"
}
},
{
"name": "Giant Test",
"slug": "giant",
"size": "48px"
},
{
"name": "Display Small Test",
"slug": "display-small",
"size": "32px"
},
{
"name": "Display Large Test",
"slug": "display-large",
"size": "48px"
}
]
}
},
packages/block-editor/src/components/global-styles/typography-panel.js
Outdated
Show resolved
Hide resolved
packages/components/src/font-size-picker/font-size-picker-toggle-group.tsx
Show resolved
Hide resolved
| size = 'default', | ||
| units: unitsProp = DEFAULT_UNITS, | ||
| value, | ||
| valueMode = 'literal', |
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.
Is there a condition for which this should be 'slug'?
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's literal when you use a custom font size that is not a preset, but it's slug when you use a preset. Previously the font size was only working with size, so you were not able to select a different font size if the size property held the same value, even if it was a fixed vs. a fluid value. Now it differentiates on the slugs of you use a preset, so when using for example TT5 it can hold small, medium, large and so on, and custom sizes well you can add via the typography interface.
packages/components/src/font-size-picker/font-size-picker-select.tsx
Outdated
Show resolved
Hide resolved
Thank you for your feedback @ramonjd! I think the code was a bit confusing, I just removed the remaining |
aaronrobertshaw
left a comment
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.
Thanks for all the hard work on this @luminuu 🙇
I'm not fully up-to-date on the history and context of this PR but I've taken the latest changes for a spin in both the site editor with global styles and the block editor.
It is testing as per the test instructions for me.
✅ Could replicate issue with toggle group control on trunk
✅ Could replicate issue with font size picker dropdown on trunk
✅ This PR fixes selection of preset font sizes for the toggle group control
✅ This PR fixes selection when picker is using the dropdown
✅ When using this PR I could not replicate reported custom value issue
This is very close I think. Just a few remaining pieces of earlier feedback to address and it should be good to go.
The unit tests don't need to be a blocker and could be added via a follow-up.
Ah got it, thanks for that. I retested and things are working well. Just curious if other folks can see the selected preset disappearing after save (this is for toggle + select, block + global styles) Kapture.2025-10-20.at.11.13.41.mp4Here's the JSON I'm using to test: "typography": {
"defaultFontSizes": false,
"fluid": true,
"fontSizes": [
{
"name": "Extra Large Test",
"slug": "extra-large",
"size": "24px"
},
{
"name": "Huge Test",
"slug": "huge",
"size": "32px",
"fluid": {
"min": "16px",
"max": "32px"
}
},
{
"name": "Giant Test",
"slug": "giant",
"size": "48px"
},
{
"name": "Display Small Test",
"slug": "display-small",
"size": "32px"
},
{
"name": "Display Large Test",
"slug": "display-large",
"size": "48px"
}
]
}
}, |
|
@ramonjd Thanks for the extra debugging and testing here. I can replicate the issue you reported. I used empty theme and simply added two font size presets with matching font size values. From my debugging so far the issue is related to the different preset data formats between global styles and block supports. I believe block supports will encode to a Quickly updating the |
|
@luminuu I hope you don't mind but I took the liberty of pushing a quick commit that I believe fixes the issue @ramonjd highlighted. This quick fix has the selection of font size presets working again for me in the Global Styles typography panel. Screen.Recording.2025-10-20.at.5.49.43.pm.mp4It appears our CI is down due to an AWS outage. @ramonjd if you can re-test and confirm this fix, could you also then kick off the e2es as well? |
|
Thank you for the quick fix @aaronrobertshaw! I'll work on the other feedback @ramonjd has provided today, if there's anything no longer relevant just mark it as resolved. |
|
I've now figured out why the one Playwright test is failing: in trunk, when selecting a font size preset from the dropdown, the I assume this needs to be fixed and we're not changing the Playwright tests, is that correct? @ramonjd |
…filled in from selected preset
|
Figured out the issue with the failing checks myself and did another commit. I think I have addressed all feedback, let me know if there's still something unclear / I should take a look at. |
|
Thanks @luminuu and @aaronrobertshaw This is testing well for me!
I appreciate all the hard work 🙇🏻 @t-hamano do you think we can still get this PR into 6.9 in the next package update? |
ramonjd
left a comment
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.
Thanks for sticking with this one @luminuu
And for the tests!
I think this is going to be a high-impact bug fix.
This PR adds a new prop to a component, so it's strictly an enhancement. Gutenberg 21.9 RC1 and RC2 have already been released, but if RC3 is planned before 6.9 Beta1, this PR could be cherry-picked. cc @ellatrix @priethor However, since this PR fixes many bugs at the same time, I think it would be fine to backport it to Beta1 or later. |
|
I think it's okay to include this in beta cycles. |
|
Confirming we are having a GB RC3 with the latest cherry-picked PRs, but I agree it's fine to ship this post-Beta1. |
t-hamano
left a comment
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.
Is there anything else we should do? If not, let's backport it to 6.9 Beta2.
Added documentation for the 'valueMode' prop in font size picker.
…lue (#71703) Co-authored-by: luminuu <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: mirka <[email protected]> Co-authored-by: hanneslsm <[email protected]> Co-authored-by: karmatosed <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: priethor <[email protected]> Co-authored-by: pagelab <[email protected]> Co-authored-by: SH4LIN <[email protected]> Co-authored-by: andersnoren <[email protected]> Co-authored-by: matiasbenedetto <[email protected]> Co-authored-by: susurruses <[email protected]> Co-authored-by: uniquesolution <[email protected]>
|
I just cherry-picked this PR to the wp/6.9 branch to get it included in the next release: d14bfe4 |
…lue (WordPress#71703) Co-authored-by: luminuu <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: mirka <[email protected]> Co-authored-by: hanneslsm <[email protected]> Co-authored-by: karmatosed <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: priethor <[email protected]> Co-authored-by: pagelab <[email protected]> Co-authored-by: SH4LIN <[email protected]> Co-authored-by: andersnoren <[email protected]> Co-authored-by: matiasbenedetto <[email protected]> Co-authored-by: susurruses <[email protected]> Co-authored-by: uniquesolution <[email protected]>
What?
Closes #42683
Closes #64760
Closes #71510
Closes #52191
Closes #69939
Why?
This PR solves multiple issues regarding the selection of font size preset, if those presets have the same size. Right now selecting a font size preset in the editor will result in always falling back to the first item in the list that has the exact same
sizeset.Even if a user sets custom fluid values, the original
sizevalue is stored and used as a selection reference. This causes issues in the user experience of the custom fluid values not working correctly as they just can not be selected, if the size value (which will be disabled) is not changed before entering custom fluid values.How?
This PR introduces a
selectedSlugvariable that is used in every relevant spot to hold the actual selection, instead of falling back on a specificsizethat can be added multiple times through the font size presets interface.The code fixes this issue in both selection variations: the horizontal S - M - L - XL - XXL selection like in Twenty Twenty-Five, as well as in the dropdown, if more font size presets exist than the horizontal selection can show.
I also went ahead on updating the display of the font size preset name and actual value in the dropdown, despite the issue is waiting for more Design feedback. The reason for this is I found that when not adjusting this, if the preset name was short (like
Small) and it had a fixed value, it would all be in one line. Together with items that break into two lines, this would have looked confusing, as information for different items have showed differently. I went ahead and added feedback by @karmatosed already, but this can be discussed here too.Testing Instructions
Depending on the theme it's tested and optionally additional font size presets added, both variations can be tested:
Horizontal view
0.875remas font size.Dropdown view
1remfor example.1remin the size input as well, before activating both of the fluid toggles and adding1remand3remas respective values.Screenshots or screencast
The screencasts only show the dropdown version.
Before
CleanShot.2025-09-16.at.18.15.52.mp4
After
CleanShot.2025-09-16.at.18.10.29.mp4