Skip to content

Commit e097720

Browse files
- errorText and state only appears when checkbox is unchecked;
- update scss to use vars; - add more examples to states page;
1 parent 34fd510 commit e097720

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

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

Lines changed: 30 additions & 11 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;
@@ -116,11 +117,11 @@ input {
116117
}
117118

118119
.checkbox-bottom .error-text {
119-
color: globals.$ion-semantics-danger-800;
120+
color: globals.$ion-text-danger;
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);
@@ -197,11 +197,17 @@ input {
197197

198198
// Ionic Design Checkbox Invalid
199199
// --------------------------------------------------
200-
:host(.ion-invalid) {
200+
:host(.ion-invalid:not(.checkbox-checked)) {
201201
--focus-ring-color: #{globals.$ion-border-focus-error};
202202

203203
.native-wrapper {
204-
border-color: globals.$ion-semantics-danger-800;
204+
border-color: globals.$ion-border-danger-default;
205+
}
206+
}
207+
208+
:host(.ion-invalid:not(.checkbox-checked).checkbox-disabled) {
209+
.native-wrapper {
210+
border-color: globals.$ion-border-danger-default;
205211
}
206212
}
207213

@@ -222,7 +228,7 @@ input {
222228
:host(.checkbox-disabled.checkbox-checked) .native-wrapper {
223229
border-width: globals.$ion-border-size-0;
224230

225-
background-color: globals.$ion-semantics-primary-base;
231+
background-color: globals.$ion-bg-primary-base-default;
226232
}
227233

228234
// Checkbox Hover
@@ -233,7 +239,9 @@ input {
233239
}
234240

235241
:host(:hover.checkbox-checked) .native-wrapper,
236-
:host(:hover.checkbox-indeterminate) .native-wrapper {
242+
:host(:hover.checkbox-checked) .checkbox-icon,
243+
:host(:hover.checkbox-indeterminate) .native-wrapper,
244+
:host(:hover.checkbox-indeterminate) .checkbox-icon {
237245
background-color: globals.$ion-semantics-primary-800;
238246
}
239247
}
@@ -248,14 +256,25 @@ input {
248256
// Checkbox: Active
249257
// --------------------------------------------------------
250258
:host(.ion-activated) .native-wrapper {
251-
background-color: globals.$ion-primitives-neutral-200;
259+
background-color: globals.$ion-bg-input-press;
252260
}
253261

254262
:host(.ion-activated.checkbox-checked) .native-wrapper,
255-
:host(.ion-activated.checkbox-indeterminate) .native-wrapper {
256-
background-color: globals.$ion-semantics-primary-900;
263+
:host(.ion-activated.checkbox-checked) .checkbox-icon,
264+
:host(.ion-activated.checkbox-indeterminate) .native-wrapper,
265+
:host(.ion-activated.checkbox-indeterminate) .checkbox-icon {
266+
background-color: globals.$ion-bg-primary-base-press;
257267
}
258268

269+
:host(.ion-activated.ion-invalid:not(.checkbox-checked)) {
270+
background-color: globals.$ion-bg-input-press;
271+
272+
.native-wrapper {
273+
border-color: globals.$ion-border-danger-press;
274+
}
275+
}
276+
277+
259278
// Ionic Design Checkbox Shapes
260279
// --------------------------------------------------
261280
:host(.checkbox-shape-soft) {

core/src/components/checkbox/checkbox.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,25 +239,30 @@ export class Checkbox implements ComponentInterface {
239239
* This element should only be rendered if hint text is set.
240240
*/
241241
private renderHintText() {
242-
const { helperText, errorText, helperTextId, errorTextId } = this;
242+
const { helperText, errorText, helperTextId, errorTextId, checked } = this;
243243

244244
/**
245245
* undefined and empty string values should
246246
* be treated as not having helper/error text.
247247
*/
248-
const hasHintText = !!helperText || !!errorText;
249-
if (!hasHintText) {
248+
const hasHelperText = !!helperText;
249+
const hasErrorText = (!!errorText && !checked);
250+
if (!hasHelperText && !hasErrorText) {
250251
return;
251252
}
252253

253254
return (
254255
<div class="checkbox-bottom">
255-
<div id={helperTextId} class="helper-text" part="supporting-text helper-text">
256-
{helperText}
257-
</div>
258-
<div id={errorTextId} class="error-text" part="supporting-text error-text">
259-
{errorText}
260-
</div>
256+
{hasHelperText && (
257+
<div id={helperTextId} class="helper-text" part="supporting-text helper-text">
258+
{helperText}
259+
</div>
260+
)}
261+
{hasErrorText && (
262+
<div id={errorTextId} class="error-text" part="supporting-text error-text">
263+
{errorText}
264+
</div>
265+
)}
261266
</div>
262267
);
263268
}

core/src/components/checkbox/test/states/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ <h2>Focused, Unchecked</h2>
8181
<h2>Focused, Checked</h2>
8282
<ion-checkbox checked class="ion-focused">Enable Notifications</ion-checkbox>
8383
</div>
84+
85+
<div class="grid-item">
86+
<h2>Focused, Invalid</h2>
87+
<ion-checkbox error-text="Error text" class="ion-invalid ion-focused">Enable Notifications</ion-checkbox>
88+
</div>
89+
90+
<div class="grid-item">
91+
<h2>Disabled, Invalid</h2>
92+
<ion-checkbox disabled="true" error-text="Error text" class="ion-invalid">Enable Notifications</ion-checkbox>
93+
</div>
8494
</div>
8595
</ion-content>
8696
</ion-app>

0 commit comments

Comments
 (0)