-
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: Ensure text label contrast checking works with CSS variables #47373
Merged
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0c5c13b
ColorPalette: Ensure text label contrast checking works with CSS vari…
t-hamano c4cd604
use `useEffect` to get normalized color value
t-hamano ebae2d7
Update changelog
t-hamano 9327bc9
Try to detect actual color from rgba
t-hamano 2eec7a6
Resolve conflict
t-hamano 98bf1dc
Use function to get the composite background color
t-hamano 75f9c62
Rewrite useEffect with useCallback
t-hamano 0489602
Merge branch 'trunk' into fix/colorpalette-contrast-check
t-hamano 30ae6bc
Don't consider transparent color
t-hamano 011e099
Don't use ref, simplify normalizeColorValue() function
t-hamano dc62b0f
Add JSDoc
t-hamano 2b845f7
Add unit tests
t-hamano b020ea2
Fix conflicts
t-hamano e225bf5
Refactor unit tests
t-hamano 2945982
Refactor unit test
t-hamano 969bf03
Merge branch 'trunk' into fix/colorpalette-contrast-check
t-hamano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not ideal, of course, but better than nothing. I'm not sure if @mirka has any idea to who we could get
getComputedStyle
to work our tests (afterall, it seems to work as expected inTheme
's tests).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.
Or even @jsnajdr , given his recent work on
getComputedStyle
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.
JSDOM has a very limited support for CSS, and it doesn't expand CSS variables to their real values. That means that
normalizeValue
is not possible to unit test with Jest and JSDOM. I would consider if I want to keep the unit test at all.A less harsh way to "fake" the CSS value is to set the style on the tested element itself:
Then
getComputedStyle( element )
will find this style and will return it.By the way, the
normalizeValue
function would be better off if its second param was just the element, not a ref: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.
Thank you, Jarda!
Good point. @t-hamano , would you mind trying out this approach?
Agreed! Although this change should have been applied in a previous commit
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.
Thank you for the advice! Perhaps I was thinking too hard. I think we handled it well with 2945982.