Skip to content

Commit 7f904d0

Browse files
fix(checkbox): improve states and colors (#30559)
Issue number: internal --------- <!-- 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 new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - update scss to use vars; - add more examples to states page; - now the invalid state is only possible for unchecked checkboxes; ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> [basic](https://ionic-framework-git-rou-12073-ionic1.vercel.app/src/components/checkbox/test/basic?ionic:theme=ionic) [indeterminate](https://ionic-framework-git-rou-12073-ionic1.vercel.app/src/components/checkbox/test/indeterminate?ionic:theme=ionic) [Bottom Content](https://ionic-framework-git-rou-12073-ionic1.vercel.app/src/components/checkbox/test/bottom-content?ionic:theme=ionic) [States](https://ionic-framework-git-rou-12073-ionic1.vercel.app/src/components/checkbox/test/states?ionic:theme=ionic) --------- Co-authored-by: ionitron <[email protected]>
1 parent 79a12ce commit 7f904d0

21 files changed

+49
-9
lines changed

core/src/components/checkbox/checkbox.ionic.scss

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
// Size
2929
--size: #{globals.$ion-scale-600};
30-
--checkbox-background-checked: #{globals.$ion-semantics-primary-base};
30+
--checkbox-background: #{globals.$ion-bg-input-default};
31+
--checkbox-background-checked: #{globals.$ion-bg-primary-base-default};
3132
--border-color-checked: #{globals.$ion-semantics-primary-base};
3233
--checkmark-color: #{globals.$ion-primitives-base-white};
3334
--transition: none;
@@ -120,7 +121,7 @@ input {
120121
}
121122

122123
.checkbox-bottom .helper-text {
123-
color: globals.$ion-primitives-neutral-800;
124+
color: globals.$ion-text-subtlest;
124125
}
125126

126127
// Label Placement - Start
@@ -187,7 +188,6 @@ input {
187188

188189
// Checked / Indeterminate Checkbox
189190
// ---------------------------------------------
190-
191191
:host(.checkbox-checked) .native-wrapper,
192192
:host(.checkbox-indeterminate) .native-wrapper {
193193
border-color: var(--border-color-checked);
@@ -199,9 +199,12 @@ input {
199199
// --------------------------------------------------
200200
:host(.ion-invalid) {
201201
--focus-ring-color: #{globals.$ion-border-focus-error};
202+
}
202203

204+
:host(.ion-invalid:not(.checkbox-checked)),
205+
:host(.ion-invalid:not(.checkbox-checked).checkbox-disabled) {
203206
.native-wrapper {
204-
border-color: globals.$ion-semantics-danger-800;
207+
border-color: globals.$ion-border-danger-default;
205208
}
206209
}
207210

@@ -222,7 +225,7 @@ input {
222225
:host(.checkbox-disabled.checkbox-checked) .native-wrapper {
223226
border-width: globals.$ion-border-size-0;
224227

225-
background-color: globals.$ion-semantics-primary-base;
228+
background-color: globals.$ion-bg-primary-base-default;
226229
}
227230

228231
// Checkbox Hover
@@ -233,7 +236,9 @@ input {
233236
}
234237

235238
:host(:hover.checkbox-checked) .native-wrapper,
236-
:host(:hover.checkbox-indeterminate) .native-wrapper {
239+
:host(:hover.checkbox-checked) .checkbox-icon,
240+
:host(:hover.checkbox-indeterminate) .native-wrapper,
241+
:host(:hover.checkbox-indeterminate) .checkbox-icon {
237242
background-color: globals.$ion-semantics-primary-800;
238243
}
239244
}
@@ -248,12 +253,22 @@ input {
248253
// Checkbox: Active
249254
// --------------------------------------------------------
250255
:host(.ion-activated) .native-wrapper {
251-
background-color: globals.$ion-primitives-neutral-200;
256+
background-color: globals.$ion-bg-input-press;
252257
}
253258

254259
:host(.ion-activated.checkbox-checked) .native-wrapper,
255-
:host(.ion-activated.checkbox-indeterminate) .native-wrapper {
256-
background-color: globals.$ion-semantics-primary-900;
260+
:host(.ion-activated.checkbox-checked) .checkbox-icon,
261+
:host(.ion-activated.checkbox-indeterminate) .native-wrapper,
262+
:host(.ion-activated.checkbox-indeterminate) .checkbox-icon {
263+
background-color: globals.$ion-bg-primary-base-press;
264+
}
265+
266+
:host(.ion-activated.ion-invalid:not(.checkbox-checked)) {
267+
background-color: globals.$ion-bg-input-press;
268+
269+
.native-wrapper {
270+
border-color: globals.$ion-border-danger-press;
271+
}
257272
}
258273

259274
// Ionic Design Checkbox Shapes

core/src/components/checkbox/test/states/checkbox.e2e.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ configs({ modes: ['ios', 'md', 'ionic-md'], directions: ['ltr'] }).forEach(({ ti
1515
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-disabled`));
1616
});
1717

18+
test('should render disabled invalid checkbox correctly', async ({ page }) => {
19+
await page.setContent(
20+
`
21+
<ion-checkbox disabled="true" error-text="Error text" class="ion-invalid">Label</ion-checkbox>
22+
`,
23+
config
24+
);
25+
26+
const checkbox = page.locator('ion-checkbox');
27+
await expect(checkbox).toHaveScreenshot(screenshot(`invalid-checkbox-disabled`));
28+
});
29+
1830
test('should render disabled checked checkbox correctly', async ({ page }) => {
1931
await page.setContent(
2032
`
@@ -57,6 +69,7 @@ configs({ modes: ['ios', 'md', 'ionic-md'], directions: ['ltr'] }).forEach(({ ti
5769
<div id="checkboxes" style="padding: 8px">
5870
<ion-checkbox class="ion-focused">Label</ion-checkbox>
5971
<ion-checkbox class="ion-focused" checked>Label</ion-checkbox>
72+
<ion-checkbox class="ion-invalid ion-focused">Label</ion-checkbox>
6073
</div>
6174
`,
6275
config
Loading
Loading
Loading
-45 Bytes
Loading
954 Bytes
Loading
807 Bytes
Loading
-22 Bytes
Loading
713 Bytes
Loading

0 commit comments

Comments
 (0)