-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Style engine: allow for zero values for CSS properties in the style engine #41561
Conversation
Create an opinionated, dedicated method so we can use it elsewhere if required.
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.
LGTM, tests pass, the padding support still works correctly in real world usage, and it sounds good to me to have a specific function for checking the value is valid 👍
Thanks for tidying things up!
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.
LGTM.
✅ Tests pass
✅ Padding support works in the editor
Just left a small question though certainly nothing that blocks this.
@@ -165,6 +184,11 @@ protected static function get_slug_from_preset_value( $style_value, $property_ke | |||
*/ | |||
protected static function get_classnames( $style_value, $style_definition ) { | |||
$classnames = array(); | |||
|
|||
if ( empty( $style_value ) ) { |
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.
Minor question: Is it worth future-proofing this a little in case the classname generation extends beyond presets in future?
This check would still return a false positive for '0'
. I'm thinking of things like the Cover blocks opacity classes like has-background-dim-0
.
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.
That's an interesting case, thanks for raising it.
There's no requirement for such values here yet, but if we hit the cover block one day it'll be there.
I was just trying to prevent the code doing any further work for now. But there's no harm in removing the check since it wasn't there before. 👍
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.
if ( empty( $style_value ) ) { | |
if ( empty( $style_value ) && '0' !== $style_value ) { |
I was more suggesting that we tweak that check to allow '0'
values rather than remove it. Sorry for the confusion.
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.
All good. I read the comment wrong. In that case it's probably safe to leave as it was until we get to individual blocks in 2025 😄
The fact that the style engine generates classes at all is still a bit contentious, that is, whether it should just stick to CSS.
… in generate takes care of values we don't care about.
What?
Allow for zero values for CSS properties in the style engine.
Why?
Just in case we come across a style value of
'0'
, e.g.,padding: '0'
.This PR ensures the previous
empty()
check doesn't fail for '0'.How?
Create an opinionated, dedicated method so we can use it elsewhere if required.
Testing Instructions