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

Custom property output by spacing sizes is incorrect for slugs containing numbers #44349

Closed
fabiankaegy opened this issue Sep 22, 2022 · 4 comments · Fixed by #44406
Closed
Assignees
Labels
[Package] Style Engine /packages/style-engine [Type] Bug An existing feature does not function as intended

Comments

@fabiankaegy
Copy link
Member

fabiankaegy commented Sep 22, 2022

Description

Using the new spacingSizes property in theme.json I noticed that the custom property that gets set as an inline style from the style engine are incorrect if the slug contains a number.

My spacing sizes look as follows:

"spacingSizes": [
        {
          "slug": "s",
          "size": "5px",
          "name": "S"
        },
        {
          "slug": "m",
          "size": "10px",
          "name": "M"
        },
        {
          "slug": "l",
          "size": "15px",
          "name": "L"
        },
        {
          "slug": "xl",
          "size": "30px",
          "name": "XL"
        },
        {
          "slug": "2xl",
          "size": "50px",
          "name": "2XL"
        },
        {
          "slug": "3xl",
          "size": "85px",
          "name": "3XL"
        }
      ]

They produce the custom properties:

<style>
--wp--preset--spacing--s: 5px;
--wp--preset--spacing--m: 10px;
--wp--preset--spacing--l: 15px;
--wp--preset--spacing--xl: 30px;
--wp--preset--spacing--2-xl: 50px;
--wp--preset--spacing--3-xl: 85px;
</style>

But the inline styles that get generated in the editor look like this:

<p style="margin-top: var(--wp--preset--spacing--2xl); margin-right: var(--wp--preset--spacing--2xl); margin-bottom: var(--wp--preset--spacing--2xl); margin-left: var(--wp--preset--spacing--2xl);">...</p>

The Inline styles are missing the additional - after any number in the slug

Step-by-step reproduction instructions

  1. Add this spacingScale to your theme.json file
"spacingSizes": [
        {
          "slug": "s",
          "size": "5px",
          "name": "S"
        },
        {
          "slug": "m",
          "size": "10px",
          "name": "M"
        },
        {
          "slug": "l",
          "size": "15px",
          "name": "L"
        },
        {
          "slug": "xl",
          "size": "30px",
          "name": "XL"
        },
        {
          "slug": "2xl",
          "size": "50px",
          "name": "2XL"
        },
        {
          "slug": "3xl",
          "size": "85px",
          "name": "3XL"
        }
      ]
  1. Try setting the margin of a block to the "2XL" setting.
  2. See issue.

Screenshots, screen recording, code snippet

CleanShot 2022-09-22 at 09 54 27

Environment info

  • WordPress 6.1 Beta 1
  • No Gutenberg Plugin

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

@fabiankaegy fabiankaegy added [Type] Bug An existing feature does not function as intended [Package] Style Engine /packages/style-engine labels Sep 22, 2022
@fabiankaegy
Copy link
Member Author

Just a note for any theme developers that might be impacted by this:

Manually adding the - to the slug does resolve the issue:

"spacingSizes": [
        {
          "slug": "s",
          "size": "5px",
          "name": "S"
        },
        {
          "slug": "m",
          "size": "10px",
          "name": "M"
        },
        {
          "slug": "l",
          "size": "15px",
          "name": "L"
        },
        {
          "slug": "xl",
          "size": "30px",
          "name": "XL"
        },
        {
          "slug": "2-xl",
          "size": "50px",
          "name": "2XL"
        },
        {
          "slug": "3-xl",
          "size": "85px",
          "name": "3XL"
        }
      ]

@fabiankaegy
Copy link
Member Author

@Mamaduka helpfully pointed out in slack, this older issue is somewhat related as it shows the trail of where this handling of adding - after numbers was introduced: #39155

@ockham
Copy link
Contributor

ockham commented Sep 22, 2022

cc/ @ramonjd b/c Style Engine 😊

@ramonjd
Copy link
Member

ramonjd commented Sep 23, 2022

Thanks for reporting this!

It's a JS fix.

I've added the fix and test coverage over in #44406

I've also added the Backport to WP Beta/RC label.

@glendaviesnz glendaviesnz moved this from Todo to In Progress in WordPress 6.1 Editor Tasks Sep 23, 2022
Repository owner moved this from In Progress to Done in WordPress 6.1 Editor Tasks Sep 23, 2022
@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Style Engine /packages/style-engine [Type] Bug An existing feature does not function as intended
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants