-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
ColorPalette utils: do not normalize undefined color values #64969
Conversation
…le values as non-simple values and therefore returning defaultView?.getComputedStyle adding tests
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@@ -92,9 +92,13 @@ export const normalizeColorValue = ( | |||
value: string | undefined, | |||
element: HTMLElement | null | |||
) => { | |||
if ( ! value || ! element ) { |
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.
There was a related conversation about how to handle null values here: #64224 (comment)
Not sure if I've grokked the outcome of that, so let me know if there's a better way to do this.
Seems to work for me 2024-09-02.15.29.58.mp4 |
Flaky tests detected in d0d336e. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10661442034
|
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.
Good catch, the code works as intended. Thank you 🙏
@@ -39,5 +39,24 @@ describe( 'ColorPalette: Utils', () => { | |||
'#ff0000' | |||
); | |||
} ); | |||
test( 'should return the value as is if the color value undefined', () => { |
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.
I'm not sure I entirely get the meaning of this test name
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.
😄 bad copy pasta. I'll fix - thanks for noticing
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, thanks for the fix @ramonjd 🙌
I appreciate the quick reviews, folks 🙇🏻 |
What?
Fixes a regression introduced by #64224
normalizeColorValue()
was treating empty style values as non-simple values and therefore returningdefaultView?.getComputedStyle
Adds tests
Why?
Empty values were being filled by an element's computed background color, which could be the site background color.
This is confusing and means that, by default, it's impossible to select a new color without adjusting the alpha value.
How?
Detecting false values and returning the value immediately.
Testing Instructions
ColorPalette
: partial support ofcolor-mix()
CSS colors #64224 and ensure that worksBefore
The default alpha value is
0
, which means, by default, any custom color cannot be seen in the canvas.Kapture.2024-09-02.at.14.46.23.mp4
After
The alpha is
100
so, by default, my custom color changes are visible on the canvas.Kapture.2024-09-02.at.14.44.36.mp4
Semi-related
color-mix()
and other color syntaxes #64638