Skip to content

Commit a97a357

Browse files
wkeeseheloiseluisojinantony01warrenmbloodkennylam
authored andcommitted
fix(icons): fix icons invisible in high contrast mode (carbon-design-system#19352)
* fix(icons): fix icons invisible in high contrast mode 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. * fix(icons): fix tooltip story Use proper color for icon, not background color. * fix(icons): remove vestigial high-contrast-mode('icon-fill') 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. * fix(icons): handle weird values for fill 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. * fix(icons): fix comment * fix(icons): fix background colors * fix(icons): fix checkmark * fix(icons): remove unused imports of high-contrast-mode * fix: remove unexpected shadow from web-component button (carbon-design-system#19347) * fix: controlled tag component for selected prop carbon-design-system#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 * fix(date-picker): clear flatpickr instance on reset (carbon-design-system#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]> * fix: modal footer buttons were not fully visible in zoom to 400 (carbon-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]> * fix(icons): another inverted background * chore(icons): fix merge error --------- Co-authored-by: Heloise Lui <[email protected]> Co-authored-by: Sojin antony <[email protected]> Co-authored-by: Warren Blood <[email protected]> Co-authored-by: kennylam <[email protected]> Co-authored-by: Preeti Bansal <[email protected]>
1 parent 9c0b4ab commit a97a357

File tree

35 files changed

+78
-195
lines changed

35 files changed

+78
-195
lines changed

packages/react/src/components/Tooltip/story.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737

3838
.sb-tooltip-trigger svg {
39-
fill: theme.$background-inverse;
39+
fill: theme.$icon-secondary;
4040
}
4141

4242
// DefinitionTooltip

packages/styles/scss/_reset.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@
172172

173173
@include type.reset();
174174

175-
/// Makes SVGs accessible in high contrast mode
175+
/// Makes SVGs accessible in high contrast mode, although it only works sporadically as other CSS selectors
176+
/// routinely override this one.
176177
/// @link https://github.com/IBM/carbon-elements/issues/345#issuecomment-466577293 Carbon-elements #345
177178
@media screen and (-ms-high-contrast: active) {
178179
svg {

packages/styles/scss/_theme.scss

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,61 @@
88
@forward './theme/theme' hide theme;
99
@use './theme/theme';
1010
@use './layer/layer-tokens';
11+
@use './utilities/custom-property';
1112

1213
/// Include the CSS Custom Properties for the active theme or a given theme on
1314
/// a selector
1415
@mixin theme($args...) {
1516
@include theme.theme($args...);
1617

18+
// If the system is in high-contrast mode, use the system defined colors. This mostly happens automatically, but
19+
// we need to do it manually for icons and selected backgrounds. Importantly, the custom properties we set here
20+
// need to override the CSS custom properties set above. See:
21+
// - https://github.com/carbon-design-system/carbon/issues/19015
22+
// - https://developer.mozilla.org/en-US/docs/Web/CSS/system-color.
23+
// - https://carbondesignsystem.com/elements/color/tokens/#icon
24+
@media screen and (-ms-high-contrast: active), (forced-colors: active) {
25+
// Icon colors specified by "fill".
26+
@include custom-property.declaration('icon-primary', ButtonText);
27+
@include custom-property.declaration('icon-secondary', ButtonText);
28+
@include custom-property.declaration('icon-interactive', ButtonText);
29+
@include custom-property.declaration('icon-disabled', GrayText);
30+
@include custom-property.declaration('icon-on-color-disabled', GrayText);
31+
32+
// Since icon-inverse and icon-on-color are generally used to indicated selected icons, use SelectedItemText.
33+
@include custom-property.declaration('icon-inverse', SelectedItemText);
34+
@include custom-property.declaration('icon-on-color', SelectedItemText);
35+
36+
// Some components currently set these values for fill, although unclear if that's valid.
37+
@include custom-property.declaration('button-disabled', GrayText);
38+
@include custom-property.declaration('interactive', ButtonText);
39+
@include custom-property.declaration('link-primary', LinkText);
40+
@include custom-property.declaration('link-primary-hover', LinkText);
41+
@include custom-property.declaration('link-secondary', LinkText);
42+
@include custom-property.declaration('link-inverse', SelectedItemText);
43+
@include custom-property.declaration(
44+
'link-inverse-hover',
45+
SelectedItemText
46+
);
47+
@include custom-property.declaration(
48+
'link-inverse-visited',
49+
SelectedItemText
50+
);
51+
@include custom-property.declaration('link-visited', VisitedText);
52+
53+
// Force a background-color for selected buttons etc., otherwise the user won't know they are selected.
54+
@include custom-property.declaration('background-selected', SelectedItem);
55+
@include custom-property.declaration(
56+
'background-selected-hover',
57+
SelectedItem
58+
);
59+
@include custom-property.declaration('background-inverse', SelectedItem);
60+
@include custom-property.declaration(
61+
'layer-selected-inverse',
62+
SelectedItem
63+
);
64+
}
65+
1766
// Note: we need to re-emit the contextual layer tokens as part of the theme
1867
// mixin. Otherwise, the layer tokens are defined at the :root level and will
1968
// not pick up the theme-specific, or zone-specific, value from the first

packages/styles/scss/components/accordion/_accordion.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
@use '../../utilities/convert';
1818
@use '../../utilities/layout';
1919
@use '../../utilities/focus-outline' as *;
20-
@use '../../utilities/high-contrast-mode' as *;
2120

2221
/// @type Value
2322
/// @access public
@@ -385,12 +384,6 @@ $content-padding: 0 0 0 $spacing-05 !default;
385384
margin-inline-start: $spacing-05;
386385
}
387386

388-
// Windows HCM fix
389-
.#{$prefix}--accordion__arrow,
390-
.#{$prefix}--accordion__item--active .#{$prefix}--accordion__arrow {
391-
@include high-contrast-mode('icon-fill');
392-
}
393-
394387
// RTL overrides
395388
[dir='rtl'] .#{$prefix}--accordion--start .#{$prefix}--accordion__heading {
396389
padding-inline: layout.density('padding-inline') 0;

packages/styles/scss/components/breadcrumb/_breadcrumb.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
.#{$prefix}--breadcrumb-item
177177
.#{$prefix}--overflow-menu:active
178178
.#{$prefix}--overflow-menu__icon {
179-
fill: $text-primary;
179+
fill: $icon-primary;
180180
}
181181

182182
.#{$prefix}--breadcrumb-menu-options:focus {

packages/styles/scss/components/button/_button.scss

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,6 @@
421421
@include high-contrast-mode('focus');
422422
}
423423

424-
// Windows HCM fix
425-
426-
.#{$prefix}--btn--ghost.#{$prefix}--btn--icon-only
427-
.#{$prefix}--btn__icon
428-
path:not([data-icon-path]):not([fill='none']),
429-
.#{$prefix}--btn--ghost.#{$prefix}--btn--icon-only .#{$prefix}--btn__icon {
430-
@include high-contrast-mode('icon-fill');
431-
}
432-
433424
// RTL overrides
434425
[dir='rtl'] .#{$prefix}--btn-set .#{$prefix}--btn:not(:focus) {
435426
box-shadow: convert.to-rem(1px) 0 0 0 $button-separator;

packages/styles/scss/components/checkbox/_checkbox.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@use '../../type' as *;
1313
@use '../../utilities/component-reset';
1414
@use '../../utilities/convert';
15+
@use '../../utilities/high-contrast-mode' as *;
1516
@use '../../utilities/skeleton' as *;
1617
@use '../../utilities/visually-hidden' as *;
1718

@@ -91,6 +92,9 @@
9192
position: absolute;
9293
border: 1px solid $icon-primary;
9394
border-radius: 2px;
95+
@include high-contrast-mode {
96+
border: 1px solid ButtonBorder;
97+
}
9498

9599
// Checkboxes with a background color look visually off against a parent container.
96100
background-color: transparent;
@@ -136,6 +140,13 @@
136140
border: none;
137141
border-width: 1px;
138142
background-color: $icon-primary;
143+
144+
// According to https://developer.mozilla.org/en-US/docs/Web/CSS/system-color, in high contrast mode, the
145+
// checkbox should be displayed using SelectedItem and SelectedItemText.
146+
@include high-contrast-mode {
147+
border: 1px solid ButtonBorder;
148+
background-color: SelectedItem;
149+
}
139150
}
140151

141152
// Display the check
@@ -326,6 +337,12 @@
326337
.#{$prefix}--checkbox:checked
327338
+ .#{$prefix}--checkbox-label::after {
328339
border-color: $text-primary;
340+
341+
// According to https://developer.mozilla.org/en-US/docs/Web/CSS/system-color, in high contrast mode, the
342+
// checkbox should be displayed using SelectedItem and SelectedItemText.
343+
@include high-contrast-mode {
344+
fill: SelectedItemText;
345+
}
329346
}
330347

331348
//-----------------------------------------------

packages/styles/scss/components/code-snippet/_code-snippet.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,6 @@ $copy-btn-feedback: $background-inverse !default;
555555
}
556556

557557
// Windows HCM fix
558-
559-
.#{$prefix}--snippet__icon {
560-
@include high-contrast-mode('icon-fill');
561-
}
562-
563558
.#{$prefix}--snippet--inline:focus {
564559
@include high-contrast-mode('focus');
565560
}

packages/styles/scss/components/data-table/expandable/_data-table-expandable.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,4 @@
481481
.#{$prefix}--table-expand__button:focus .#{$prefix}--table-expand__svg {
482482
@include high-contrast-mode('focus');
483483
}
484-
485-
.#{$prefix}--table-expand__svg {
486-
@include high-contrast-mode('icon-fill');
487-
}
488484
}

packages/styles/scss/components/data-table/sort/_data-table-sort.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@use '../../../utilities/button-reset';
1313
@use '../../../utilities/convert';
1414
@use '../../../utilities/focus-outline' as *;
15-
@use '../../../utilities/high-contrast-mode' as *;
1615

1716
/// Data table sort styles
1817
/// @access public
@@ -270,10 +269,4 @@
270269
display: block;
271270
margin-inline-end: convert.to-rem(8px);
272271
}
273-
274-
// Windows HCM fix
275-
.#{$prefix}--table-sort__icon,
276-
.#{$prefix}--table-sort__icon-unsorted {
277-
@include high-contrast-mode('icon-fill');
278-
}
279272
}

0 commit comments

Comments
 (0)