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

Fluid typography API makes impossible to set a fixed font-size #42698

Closed
matiasbenedetto opened this issue Jul 26, 2022 · 6 comments · Fixed by #42757
Closed

Fluid typography API makes impossible to set a fixed font-size #42698

matiasbenedetto opened this issue Jul 26, 2022 · 6 comments · Fixed by #42757
Assignees
Labels
[Feature] Typography Font and typography-related issues and PRs [Type] Enhancement A suggestion for improvement.

Comments

@matiasbenedetto
Copy link
Contributor

matiasbenedetto commented Jul 26, 2022

Description

If you add "fluid": true, in your theme.json you are not able to set static font size. I would expect to be able to set a fixed font size if I haven't defined, min and/or max settings. The current behavior makes it impossible to mix fluid and static font sizes definition as in the following example:

            "fluid": true,
            "fontSizes": [
                {
                    "size": "1rem",
                    "fluid": {
                        "min": "0.875rem",
                        "max": "1rem"
                    },
                    "slug": "small",
                    "name": "Small"
                },
                {
                    "size": "1.25rem",
                    "slug": "default",
                    "name": "Default"
                },

If you add a static font size, as the default font size defined in the previous snippet, it is rendered as a fluid font size even though I haven't defined fluid.min or fluid.max as this:

--wp--preset--font-size--default: clamp(0.9375rem, 0.9375rem + ((1vw - 0.48rem) * 1.803), 1.875rem);

I would expect:
--wp--preset--font-size--default: 1.25rem;

Step-by-step reproduction instructions

  1. Add the previous snippet to your theme.json
  2. Apply the default font size defined to a block
  3. Check that the font size is fluid instead of static.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.0.1
  • Gutenberg Trunk

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@matiasbenedetto matiasbenedetto added [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended labels Jul 26, 2022
@ramonjd
Copy link
Member

ramonjd commented Jul 26, 2022

If you add "fluid": true, in your theme.json you are not able to set static font size. I would expect to be able to set a fixed font size if I haven't defined, min and/or max settings. The current behavior makes it impossible to mix fluid and static font sizes definition

Thanks for reporting!

This is intended behaviour since 00c51d1.

Related discussion starts around here.

I had originally designed things to work as you describe in this issue.

What do folks think?

cc @mtias @scruffian

@ramonjd ramonjd added [Feature] Typography Font and typography-related issues and PRs [Type] Enhancement A suggestion for improvement. and removed [Type] Bug An existing feature does not function as intended [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels Jul 26, 2022
@mtias
Copy link
Member

mtias commented Jul 27, 2022

Yes, this is intended. Would an explicit fluid: false for a given size work to opt-out? We want to dial in fluid type heuristics as a general thing that work most of the time.

@matiasbenedetto
Copy link
Contributor Author

Yes, this is intended. Would an explicit fluid: false for a given size work to opt-out? We want to dial in fluid type heuristics as a general thing that work most of the time.

Yep, I think that could work.

@scruffian
Copy link
Contributor

Alternatively could you set a min and max which are the same?

@ramonjd
Copy link
Member

ramonjd commented Jul 28, 2022

Alternatively could you set a min and max which are the same?

Good point. This also works out of the box. 🎉

I'm happy to throw a PR up so there's an explicit fluid: false check as well.

@eric-michel
Copy link

eric-michel commented Aug 10, 2022

Would an explicit fluid: false for a given size work to opt-out?

I'm experimenting with this feature now, and without looking at the theme.json schema tried adding fluid: false to my smaller font sizes in the hopes that would cause those fonts to remain static in size. I think this would be a great addition as it seems very intuitive.

I was able to solve the issue by setting min and max to the same size for now.

edit: I'm way behind, clearly 😁 #42757

@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Typography Font and typography-related issues and PRs [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants