Skip to content

Commit bbdb0ca

Browse files
fix(item): ios active state has correct contrast (#27134)
<!-- Please refer to our contributing documentation for any questions on submitting a pull request, or let us know here if you need any help: https://ionicframework.com/docs/building/contributing --> <!-- Some docs updates need to be made in the `ionic-docs` repo, in a separate PR. See https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation for details. --> <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> <!-- Issues are required for both bug fixes and features. --> Issue URL: resolves #27130 The active/focus background colors on ion-item for iOS are always #000. This allows for the correct contrast on light mode. This is a problem on dark mode because the item background color defaults to #000 as well. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Updates the default active/focus colors to be the text color. This ensures that the active/focus colors are always the opposite of what the default item background color is. ## Does this introduce a breaking change? - [ ] Yes - [x] No Note: We are updating the default values of CSS Variables, but our implementation of the spec is wrong and creates color contrast issues. <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> --------- Co-authored-by: ionitron <[email protected]>
1 parent b81b0d1 commit bbdb0ca

9 files changed

+187
-2
lines changed

core/src/components/item/item.ios.scss

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@
1111
--inner-padding-end: #{$item-ios-padding-end};
1212
--inner-border-width: #{0px 0px $item-ios-border-bottom-width 0px};
1313
--background: #{$item-ios-background};
14-
--background-activated: #000;
15-
--background-focused: #000;
14+
/**
15+
* The active/focus states need
16+
* to be the opposite of the background color
17+
* so there is enough contrast. The background
18+
* defaults to var(--ion-background-color), so we
19+
* default to var(--ion-text-color) which will give us
20+
* the opposite color.
21+
* i.e. if var(--ion-background-color) is #000
22+
* then var(--ion-text-color) will be #fff.
23+
*/
24+
--background-activated: #{$text-color};
25+
--background-focused: #{$text-color};
1626
--background-hover: currentColor;
1727
--background-activated-opacity: .12;
1828
--background-focused-opacity: .15;

core/src/components/item/test/buttons/index.html

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,165 @@
1212
<script src="../../../../../scripts/testing/scripts.js"></script>
1313
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
1414
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
15+
16+
<style>
17+
/*
18+
* Dark Colors
19+
* -------------------------------------------
20+
*/
21+
22+
body.dark {
23+
--ion-color-primary: #428cff;
24+
--ion-color-primary-rgb: 66, 140, 255;
25+
--ion-color-primary-contrast: #ffffff;
26+
--ion-color-primary-contrast-rgb: 255, 255, 255;
27+
--ion-color-primary-shade: #3a7be0;
28+
--ion-color-primary-tint: #5598ff;
29+
30+
--ion-color-secondary: #50c8ff;
31+
--ion-color-secondary-rgb: 80, 200, 255;
32+
--ion-color-secondary-contrast: #ffffff;
33+
--ion-color-secondary-contrast-rgb: 255, 255, 255;
34+
--ion-color-secondary-shade: #46b0e0;
35+
--ion-color-secondary-tint: #62ceff;
36+
37+
--ion-color-tertiary: #6a64ff;
38+
--ion-color-tertiary-rgb: 106, 100, 255;
39+
--ion-color-tertiary-contrast: #ffffff;
40+
--ion-color-tertiary-contrast-rgb: 255, 255, 255;
41+
--ion-color-tertiary-shade: #5d58e0;
42+
--ion-color-tertiary-tint: #7974ff;
43+
44+
--ion-color-success: #2fdf75;
45+
--ion-color-success-rgb: 47, 223, 117;
46+
--ion-color-success-contrast: #000000;
47+
--ion-color-success-contrast-rgb: 0, 0, 0;
48+
--ion-color-success-shade: #29c467;
49+
--ion-color-success-tint: #44e283;
50+
51+
--ion-color-warning: #ffd534;
52+
--ion-color-warning-rgb: 255, 213, 52;
53+
--ion-color-warning-contrast: #000000;
54+
--ion-color-warning-contrast-rgb: 0, 0, 0;
55+
--ion-color-warning-shade: #e0bb2e;
56+
--ion-color-warning-tint: #ffd948;
57+
58+
--ion-color-danger: #ff4961;
59+
--ion-color-danger-rgb: 255, 73, 97;
60+
--ion-color-danger-contrast: #ffffff;
61+
--ion-color-danger-contrast-rgb: 255, 255, 255;
62+
--ion-color-danger-shade: #e04055;
63+
--ion-color-danger-tint: #ff5b71;
64+
65+
--ion-color-dark: #f4f5f8;
66+
--ion-color-dark-rgb: 244, 245, 248;
67+
--ion-color-dark-contrast: #000000;
68+
--ion-color-dark-contrast-rgb: 0, 0, 0;
69+
--ion-color-dark-shade: #d7d8da;
70+
--ion-color-dark-tint: #f5f6f9;
71+
72+
--ion-color-medium: #989aa2;
73+
--ion-color-medium-rgb: 152, 154, 162;
74+
--ion-color-medium-contrast: #000000;
75+
--ion-color-medium-contrast-rgb: 0, 0, 0;
76+
--ion-color-medium-shade: #86888f;
77+
--ion-color-medium-tint: #a2a4ab;
78+
79+
--ion-color-light: #222428;
80+
--ion-color-light-rgb: 34, 36, 40;
81+
--ion-color-light-contrast: #ffffff;
82+
--ion-color-light-contrast-rgb: 255, 255, 255;
83+
--ion-color-light-shade: #1e2023;
84+
--ion-color-light-tint: #383a3e;
85+
}
86+
87+
/*
88+
* iOS Dark Theme
89+
* -------------------------------------------
90+
*/
91+
92+
.ios body.dark {
93+
--ion-background-color: #000000;
94+
--ion-background-color-rgb: 0, 0, 0;
95+
96+
--ion-text-color: #ffffff;
97+
--ion-text-color-rgb: 255, 255, 255;
98+
99+
--ion-color-step-50: #0d0d0d;
100+
--ion-color-step-100: #1a1a1a;
101+
--ion-color-step-150: #262626;
102+
--ion-color-step-200: #333333;
103+
--ion-color-step-250: #404040;
104+
--ion-color-step-300: #4d4d4d;
105+
--ion-color-step-350: #595959;
106+
--ion-color-step-400: #666666;
107+
--ion-color-step-450: #737373;
108+
--ion-color-step-500: #808080;
109+
--ion-color-step-550: #8c8c8c;
110+
--ion-color-step-600: #999999;
111+
--ion-color-step-650: #a6a6a6;
112+
--ion-color-step-700: #b3b3b3;
113+
--ion-color-step-750: #bfbfbf;
114+
--ion-color-step-800: #cccccc;
115+
--ion-color-step-850: #d9d9d9;
116+
--ion-color-step-900: #e6e6e6;
117+
--ion-color-step-950: #f2f2f2;
118+
119+
--ion-item-background: #000000;
120+
121+
--ion-card-background: #1c1c1d;
122+
}
123+
124+
.ios body.dark ion-modal {
125+
--ion-background-color: var(--ion-color-step-100);
126+
--ion-toolbar-background: var(--ion-color-step-150);
127+
--ion-toolbar-border-color: var(--ion-color-step-250);
128+
--ion-item-background: var(--ion-color-step-150);
129+
}
130+
131+
/*
132+
* Material Design Dark Theme
133+
* -------------------------------------------
134+
*/
135+
136+
.md body.dark {
137+
--ion-background-color: #121212;
138+
--ion-background-color-rgb: 18, 18, 18;
139+
140+
--ion-text-color: #ffffff;
141+
--ion-text-color-rgb: 255, 255, 255;
142+
143+
--ion-border-color: #222222;
144+
145+
--ion-color-step-50: #1e1e1e;
146+
--ion-color-step-100: #2a2a2a;
147+
--ion-color-step-150: #363636;
148+
--ion-color-step-200: #414141;
149+
--ion-color-step-250: #4d4d4d;
150+
--ion-color-step-300: #595959;
151+
--ion-color-step-350: #656565;
152+
--ion-color-step-400: #717171;
153+
--ion-color-step-450: #7d7d7d;
154+
--ion-color-step-500: #898989;
155+
--ion-color-step-550: #949494;
156+
--ion-color-step-600: #a0a0a0;
157+
--ion-color-step-650: #acacac;
158+
--ion-color-step-700: #b8b8b8;
159+
--ion-color-step-750: #c4c4c4;
160+
--ion-color-step-800: #d0d0d0;
161+
--ion-color-step-850: #dbdbdb;
162+
--ion-color-step-900: #e7e7e7;
163+
--ion-color-step-950: #f3f3f3;
164+
165+
--ion-item-background: #1e1e1e;
166+
167+
--ion-toolbar-background: #1f1f1f;
168+
169+
--ion-tab-bar-background: #1f1f1f;
170+
171+
--ion-card-background: #1e1e1e;
172+
}
173+
</style>
15174
</head>
16175

17176
<body>
@@ -188,6 +347,12 @@ <h3>Avatar Start</h3>
188347
</style>
189348

190349
<script>
350+
// TODO FW-4005
351+
const params = new URL(window.location).searchParams;
352+
const dark = params.get('dark');
353+
if (dark !== null) {
354+
document.body.classList.add('dark');
355+
}
191356
const attach = document.getElementById('attachClick');
192357

193358
attach.addEventListener('click', (ev) => {

core/src/components/item/test/buttons/item.e2e.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@ test.describe('item: buttons', () => {
1515

1616
await expect(page).toHaveScreenshot(`item-buttons-diff-${page.getSnapshotSettings()}.png`);
1717
});
18+
19+
test('should not have visual regressions in dark', async ({ page, skip }) => {
20+
skip.rtl();
21+
22+
await page.goto(`/src/components/item/test/buttons?dark=true`);
23+
24+
await page.setIonViewport();
25+
26+
await expect(page).toHaveScreenshot(`item-buttons-dark-diff-${page.getSnapshotSettings()}.png`);
27+
});
1828
});
67 KB
Loading
79 KB
Loading
60.6 KB
Loading
63 KB
Loading
74.5 KB
Loading
54.1 KB
Loading

0 commit comments

Comments
 (0)