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

Spacing presets: Prevent % spacing size units being stripped by sanitize_title #43101

Merged
merged 2 commits into from
Aug 10, 2022

Conversation

glendaviesnz
Copy link
Contributor

What?

Fixes bug with % unit setting in spacingScale values in theme.json not working

Why?

% is supposed to be a valid unit for spacing sizes. sanitize_title`

How?

Adds a ternary to prevent a spacing sizes preset unit of % being passed through sanitize_title

Testing Instructions

  • Modify the unit in lib/compat/wordpress-6.1/theme.json in settings.spacing.spacingScale.unit to %
  • Add the following block code to editor, and make sure percentage padding values show correctly in editor and frontend
<!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|40","right":"var:preset|spacing|70","bottom":"var:preset|spacing|30","left":"var:preset|spacing|50"}}},"backgroundColor":"vivid-red","textColor":"background"} -->
<div class="wp-block-group has-background-color has-vivid-red-background-color has-text-color has-background" style="padding-top:var(--wp--preset--spacing--40);padding-right:var(--wp--preset--spacing--70);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--50)"><!-- wp:paragraph -->
<p>Percent should work</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

Screenshots

Before:
Screen Shot 2022-08-10 at 10 29 31 AM

After:
Screen Shot 2022-08-10 at 10 28 43 AM

@glendaviesnz glendaviesnz added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Aug 9, 2022
@glendaviesnz glendaviesnz self-assigned this Aug 9, 2022
Copy link
Contributor

@scruffian scruffian left a comment

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Ben Dwyer <ben@scruffian.com>
@glendaviesnz glendaviesnz merged commit 8db06ed into trunk Aug 10, 2022
@glendaviesnz glendaviesnz deleted the fix/spacing-sizes-percent-bug branch August 10, 2022 02:39
@github-actions github-actions bot added this to the Gutenberg 13.9 milestone Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants