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

Theme editor font-size with number creates mismatch between font-size slug and block class #31629

Closed
justintadlock opened this issue May 8, 2021 · 13 comments
Labels
CSS Styling Related to editor and front end styles, CSS-specific issues. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Needs Testing Needs further testing to be confirmed. [Type] Bug An existing feature does not function as intended

Comments

@justintadlock
Copy link
Contributor

When registering a custom font-size that begins with a number in theme.json, the CSS output doesn't match the class name. I tested this with a slug of 2xl.

The CSS that Gutenberg outputs is:

:root { --wp--preset--font-size--2xl: 30px; }

.has-2xl-font-size { font-size: 30px !important; }

However, when applying it to a block via the Font Size control under the Typography tab, it adds a hyphen between the 2 and xl. The block CSS class becomes has-font-size-2-xl like so:

<h1 class="has-2-xl-font-size">Hello, World!</h1>

theme.json code:

{
	"settings": {
		"defaults": {
			"typography": {
				"fontSizes": [
					{
						"slug" : "2xl",
						"name" : "2 XL",
						"size" : "30px"
					}
                                ]
                        }
                }
        }
}
@skorasaurus
Copy link
Member

related #26940

@annezazu annezazu added [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended CSS Styling Related to editor and front end styles, CSS-specific issues. labels May 17, 2021
@annezazu
Copy link
Contributor

@ntsekouras might you be able to share some context here?

@ntsekouras
Copy link
Contributor

--cc @nosolosw @jorgefilipecosta

@oandregal
Copy link
Member

oandregal commented May 31, 2021

Thanks for the report @justintadlock Going to consolidate this into #32347 as the issue is a bit larger than numbers (also affects camelCased slugs).

@oandregal
Copy link
Member

There's a fix at #32352

@justintadlock
Copy link
Contributor Author

Just confirming that #32352 fixed this.

@justintadlock
Copy link
Contributor Author

Formally noting that this issue is no longer fixed as of #32742 and #32766. The first ticket reverted the fix. The second ticket changed this in a way that does not respect valid, theme-defined slugs.

I have further proposed a compromise that would allow theme authors to address this in their themes: #32347 (comment)

@skorasaurus
Copy link
Member

skorasaurus commented Aug 17, 2021

issue for include this in documentation #19285

@skorasaurus
Copy link
Member

skorasaurus commented Nov 23, 2021

@justintadlock can you confirm this has been fixed in the current version of Gutenberg; should have been fixed in #35751 ?

@skorasaurus skorasaurus added the Needs Testing Needs further testing to be confirmed. label Nov 23, 2021
@skorasaurus
Copy link
Member

I'm no longer able to reproduce this as you instructed; the CSS outputs are all now 2-xl.
please reopen if you're still experiencing this.

@coreyworrell
Copy link
Contributor

Noticing issue mentioned here: #34509. I have 16x9 that is converted to wp--custom--aspect--16-x-9, which causes issues because we're reading from theme.json in PHP for autosuggest for class names as well as variables in Stylus. For PHP I can run the key name through _wp_to_kebab_case I suppose, but there is obviously no equivalent in Stylus/SCSS/etc. Not sure if there is any good solution though.

@justintadlock
Copy link
Contributor Author

The only way I have found to handle this across the board is to name them in theme.json as WP would output them. So, instead of using 16x9 in theme.json, literally type out 16-x-9.

This will make sure it's consistent everywhere.

@coreyworrell
Copy link
Contributor

@justintadlock yeah, that makes sense. But right now we use them for utility classes, like aspect:16x9, and it just isn't quite as nice to be forced to use aspect:16-x-9. But it kind of is an edge case I suppose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Styling Related to editor and front end styles, CSS-specific issues. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Needs Testing Needs further testing to be confirmed. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

6 participants