-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(icons): fix icons invisible in high contrast mode #19352
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
fix(icons): fix icons invisible in high contrast mode #19352
Conversation
If the system has a dark high-contrast theme, then icons need to be displayed in white (or a light color), and vice-versa. Otherwise, icons become invisible. Importantly, this must happen regardless of the Carbon theme setting. Fixes carbon-design-system#17147, carbon-design-system#18830, carbon-design-system#19015, carbon-design-system#19023, carbon-design-system#19140.
✅ Deploy Preview for v11-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v11-carbon-react ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #19352 +/- ##
=======================================
Coverage 84.91% 84.91%
=======================================
Files 373 373
Lines 14504 14504
Branches 4794 4792 -2
=======================================
Hits 12316 12316
- Misses 2040 2041 +1
+ Partials 148 147 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Use proper color for icon, not background color.
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.
Great, thank you so much for working on this!
I've been reviewing all the issues and your updates:
For @include high-contrast-mode('icon-fill')
- try removing it in this PR if possible, so I can review it here.
I tested #17147, #18830, #19015, and #19023 - they all look good, thanks 🎉
I tested #19140 and it still shows the same behavior as the issue. I recorded a quick video so you can take a look. I also saw that @mariyageorge01 made some changes in her PR, I tested it and it works as expected. Maybe we can wait for your PR to be merged first, and then she can continue with her updates? What do you think?
ContentSwitcher.mp4
When you use standard tokens like $icon-primary you don't need it anymore. Note: I didn't convert $support-error and $support-warning usages to a system color. Previously the inline notification icon 🚫 was converted from red to ButtonText. Also $support-error and $support-warning usages in _list-box.scss. Also, inline-notification has a dodgy use of $black-100 that I didn't change.
Replace $text-primary with $icon-primary as they are the same. Likewise $tab-text-disabled --> $icon-disabled. Updated _theme.scss to handle the other weird fill settings.
OK, great, done. Note: I didn't convert
Right, I only addressed the
I think that makes sense. |
Hey @wkeese, I did some new tests, and with your changes we were able to fix not only the issues you were working on, but also other issues that weren’t even on our radar. Thanks for that! Just one detail: the Also, the Grid: Grid.mp4 |
Good catch. This is complicated because Carbon has the idea of inverted colors, but that's not a thing in high-contrast mode. MDN (https://developer.mozilla.org/en-US/docs/Web/CSS/system-color) suggests that checkmarks should use ![]() I could get the white-on-black inverted color effect by (for example) setting the foreground-color to
Yah, I think that was broken before my changes. The problem is that the grid columns in the story are suddenly missing the PS: I also found the cause of that Grid story failure, it started with #19189 (unrelated to my PR). |
…19228 (carbon-design-system#19231) * fix: controlled tag component for selected prop carbon-design-system#19228 * fix: fix tests for tag * fix: controlled tag component for selected prop carbon-design-system#19228 * fix: controlled tag added a default selected prop and tests carbon-design-system#19228 * fix: controlled tag added a default selected prop and tests carbon-design-system#19228 * fix: controlled tag added a default selected prop and tests carbon-design-system#19228 * fix: controlled tag fix tests carbon-design-system#19228 * fix: add profile * fix: add profile
…stem#19239) * fix(date-picker): clear flatpickr instance on reset * fix(date-picker): clear flatpickr instance on reset * fix(date-picker): update comments and storybook docs to clarify changes * fix(date-picker): update comments and storybook docs to clarify changes * Update packages/react/src/components/DatePicker/DatePicker.tsx Co-authored-by: kennylam <[email protected]> --------- Co-authored-by: kennylam <[email protected]>
…on-design-system#19288) * fix: modal footer buttons were not fully visible in zoom to 400 * fix: added test story * fix: remove test story --------- Co-authored-by: Heloise Lui <[email protected]>
BTW @tay1orjones, do you know why [at least in some settings], ![]() Regardless, I think this PR is ready to merge. If we find any other issues we can fix them incrementally. |
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 tested this again and everything works as expected. Thanks again @wkeese! 🚀
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.
tested and LGTM as well!
8f0cb4f
Closes #17147, #18830, #19015, #19023, and partially fixes #19140.
Also fixes problems like showing the selected tab in UIShell / SidePanel.
Likely also fixes similar problems in @carbon/ibm-products.
Refs #8489.
If the system has a dark high-contrast theme, then icons need to be displayed in white (or a light color), and vice-versa. Otherwise, icons become invisible (black on black or white on white). Importantly, the icon color needs to be set relative to the system's high contrast theme regardless of which Carbon theme is selected.
Although Carbon already has a mixin for this, it is not used consistently, and it would be labor-intensive, bloat the code, and error-prone to do so. Because you basically would need to call the mixin every time you set a
fill
, which is done hundreds of times. For example:And as I wrote in #19015, you also need to worry about CSS precedence, so you might think you've fixed a bug, but it isn't fixed in all cases.
So instead, this PR goes to the root of the issue by just overriding the value of
--cds-icon-primary
CSS property referenced by the$icon-primary
SCSS variable. Likewise for similar CSS properties. For example, consider this story, in the G100 theme. There's this existing CSS:But in high contrast mode, it's now overridden by:
I also removed the current 27 calls to:
Plus a few other places that were manually setting
fill
toButtonText
, but now no longer need to do so.Changelog
New
--cds-icon-primary
) when the system is in high contrast mode.Testing / Reviewing
Tested in Storybook on Windows 11, using the Aquatic and Desert themes.
Note that you can emulate forced-mode on Mac in Chrome (see https://cssence.com/2024/forced-colors-mode-strategies/), which is useful if you don't have a PC handy. Just open Chrome DevTools, hit Ctrl/Cmd+Shift+P, type “forced”, and you’ll find the option to "Emulate CSS forced-colors: active".
PR Checklist
As the author of this PR, before marking ready for review, confirm you:
More details can be found in the pull request guide