Skip to content

Commit 6fa5709

Browse files
authored
fix(checkbox): tickmark not rendered correctly in indigo theme (#15080)
1 parent 4a49587 commit 6fa5709

File tree

3 files changed

+255
-129
lines changed

3 files changed

+255
-129
lines changed

projects/igniteui-angular/src/lib/checkbox/checkbox.component.ts

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import {
1212
Renderer2,
1313
Optional,
1414
Self,
15-
booleanAttribute
15+
booleanAttribute,
16+
inject,
17+
DestroyRef
1618
} from '@angular/core';
1719
import { ControlValueAccessor, NgControl, Validators } from '@angular/forms';
1820
import { IgxRippleDirective } from '../directives/ripple/ripple.directive';
1921
import { IBaseEventArgs, mkenum } from '../core/utils';
2022
import { EditorProvider, EDITOR_PROVIDER } from '../core/edit-provider';
21-
import { noop, Subject } from 'rxjs';
23+
import { noop, Subject, Subscription } from 'rxjs';
2224
import { takeUntil } from 'rxjs/operators';
2325
import { IgxTheme, ThemeService } from '../services/theme/theme.service';
2426

@@ -287,6 +289,58 @@ export class IgxCheckboxComponent implements EditorProvider, AfterViewInit, Cont
287289
@HostBinding('class.igx-checkbox')
288290
public cssClass = 'igx-checkbox';
289291

292+
/**
293+
* Returns if the component is of type `material`.
294+
*
295+
* @example
296+
* ```typescript
297+
* let checkbox = this.checkbox.material;
298+
* ```
299+
*/
300+
@HostBinding('class.igx-checkbox--material')
301+
protected get material() {
302+
return this.theme === 'material';
303+
}
304+
305+
/**
306+
* Returns if the component is of type `indigo`.
307+
*
308+
* @example
309+
* ```typescript
310+
* let checkbox = this.checkbox.indigo;
311+
* ```
312+
*/
313+
@HostBinding('class.igx-checkbox--indigo')
314+
protected get indigo() {
315+
return this.theme === 'indigo';
316+
}
317+
318+
/**
319+
* Returns if the component is of type `bootstrap`.
320+
*
321+
* @example
322+
* ```typescript
323+
* let checkbox = this.checkbox.bootstrap;
324+
* ```
325+
*/
326+
@HostBinding('class.igx-checkbox--bootstrap')
327+
protected get bootstrap() {
328+
return this.theme === 'bootstrap';
329+
}
330+
331+
/**
332+
* Returns if the component is of type `fluent`.
333+
*
334+
* @example
335+
* ```typescript
336+
* let checkbox = this.checkbox.fluent;
337+
* ```
338+
*/
339+
@HostBinding('class.igx-checkbox--fluent')
340+
protected get fluent() {
341+
return this.theme === 'fluent';
342+
}
343+
290344
/**
291345
* Sets/gets whether the checkbox component is on focus.
292346
* Default value is `false`.
@@ -410,42 +464,57 @@ export class IgxCheckboxComponent implements EditorProvider, AfterViewInit, Cont
410464
* @internal
411465
*/
412466
public inputId = `${this.id}-input`;
467+
413468
/**
414469
* @hidden
415470
*/
416471
protected _onChangeCallback: (_: any) => void = noop;
472+
417473
/**
418474
* @hidden
419475
*/
420476
private _onTouchedCallback: () => void = noop;
477+
421478
/**
422479
* @hidden
423480
* @internal
424481
*/
425482
protected _checked = false;
483+
426484
/**
427485
* @hidden
428486
* @internal
429487
*/
430-
private _required = false;
488+
protected theme: IgxTheme;
431489

432490
/**
433491
* @hidden
434492
* @internal
435493
*/
436-
protected theme: IgxTheme = 'material';
494+
private _required = false;
495+
private elRef = inject(ElementRef);
496+
private _theme$ = new Subject<IgxTheme>();
497+
private _subscription: Subscription;
498+
private destroyRef = inject(DestroyRef);
437499

438500
constructor(
439501
protected cdr: ChangeDetectorRef,
440502
protected renderer: Renderer2,
441503
protected themeService: ThemeService,
442504
@Optional() @Self() public ngControl: NgControl,
443505
) {
444-
this.theme = this.themeService?.globalTheme;
445-
446506
if (this.ngControl !== null) {
447507
this.ngControl.valueAccessor = this;
448508
}
509+
510+
this.theme = this.themeService.globalTheme;
511+
512+
this._subscription = this._theme$.asObservable().subscribe(value => {
513+
this.theme = value as IgxTheme;
514+
this.cdr.detectChanges();
515+
});
516+
517+
this.destroyRef.onDestroy(() => this._subscription.unsubscribe());
449518
}
450519

451520
/**
@@ -461,6 +530,13 @@ export class IgxCheckboxComponent implements EditorProvider, AfterViewInit, Cont
461530
this.cdr.detectChanges();
462531
}
463532
}
533+
534+
const theme = this.themeService.getComponentTheme(this.elRef);
535+
536+
if (theme) {
537+
this._theme$.next(theme);
538+
this.cdr.markForCheck();
539+
}
464540
}
465541

466542
/** @hidden @internal */

projects/igniteui-angular/src/lib/core/styles/components/checkbox/_checkbox-component.scss

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,9 @@
1818
@extend %cbx-ripple--hover !optional;
1919
}
2020

21-
@include e(composite) {
22-
@extend %cbx-composite--hover !optional;
23-
}
24-
2521
@include e(composite-mark) {
2622
@extend %cbx-composite-mark--fluent !optional;
2723
}
28-
29-
@include e(label) {
30-
@extend %cbx-label--hover !optional;
31-
}
3224
}
3325

3426
&:active {
@@ -68,6 +60,32 @@
6860
@extend %cbx-ripple !optional;
6961
}
7062

63+
@include m(bootstrap) {
64+
@include e(composite) {
65+
&:hover {
66+
@extend %cbx-composite--hover !optional;
67+
}
68+
}
69+
}
70+
71+
@include m(indigo) {
72+
@include e(composite) {
73+
&:hover {
74+
@extend %cbx-composite--hover !optional;
75+
}
76+
}
77+
78+
@include e(composite-mark) {
79+
@extend %cbx-composite-mark-indigo !optional;
80+
}
81+
82+
@include e(label) {
83+
&:hover {
84+
@extend %cbx-label--hover !optional;
85+
}
86+
}
87+
}
88+
7189
@include m(invalid) {
7290
@include e(composite) {
7391
@extend %cbx-composite--invalid !optional;
@@ -127,26 +145,54 @@
127145
}
128146

129147
&:hover {
130-
@extend %igx-checkbox--focused-hovered !optional;
131-
132148
@include e(ripple) {
133149
@extend %cbx-ripple--focused !optional;
134150
}
135151
}
136152
}
137153

154+
@include mx(indigo, focused) {
155+
@extend %igx-checkbox--focused-indigo !optional;
156+
}
157+
158+
@include mx(fluent, focused) {
159+
@extend %igx-checkbox--focused-fluent !optional;
160+
}
161+
162+
@include mx(bootstrap, focused) {
163+
@extend %igx-checkbox--focused-bootstrap !optional;
164+
165+
&:hover {
166+
@extend %igx-checkbox--focused-hovered !optional;
167+
}
168+
}
169+
170+
@include mx(indigo, focused, checked) {
171+
@extend %igx-checkbox--focused-checked-indigo !optional;
172+
}
173+
174+
@include mx(bootstrap, focused, checked) {
175+
@extend %igx-checkbox--focused-checked-bootstrap !optional;
176+
}
177+
138178
@include mx(focused, checked) {
139179
@extend %igx-checkbox--focused-checked !optional;
140180
}
141181

142182
@include mx(focused, invalid) {
143-
@extend %igx-checkbox--focused-invalid !optional;
144-
145183
@include e(ripple) {
146184
@extend %cbx-ripple--focused-invalid !optional;
147185
}
148186
}
149187

188+
@include mx(indigo, focused, invalid) {
189+
@extend %igx-checkbox--focused-invalid-indigo !optional;
190+
}
191+
192+
@include mx(bootstrap, focused, invalid) {
193+
@extend %igx-checkbox--focused-invalid-bootstrap !optional;
194+
}
195+
150196
@include m(indeterminate) {
151197
@extend %igx-checkbox--indeterminate !optional;
152198

@@ -178,6 +224,18 @@
178224
}
179225
}
180226

227+
@include mx(indigo, indeterminate) {
228+
@extend %igx-checkbox--indeterminate-indigo !optional;
229+
}
230+
231+
@include mx(fluent, indeterminate) {
232+
@extend %igx-checkbox--indeterminate-fluent !optional;
233+
}
234+
235+
@include mx(material, indeterminate) {
236+
@extend %igx-checkbox--indeterminate-material !optional;
237+
}
238+
181239
@include mx(invalid, indeterminate) {
182240
@extend %igx-checkbox--indeterminate--invalid !optional;
183241

@@ -188,8 +246,12 @@
188246
}
189247
}
190248

191-
@include mx(focused, indeterminate) {
192-
@extend %igx-checkbox--focused-checked !optional;
249+
@include mx(indigo, focused, indeterminate) {
250+
@extend %igx-checkbox--focused-checked-indigo !optional;
251+
}
252+
253+
@include mx(bootstrap, focused, indeterminate) {
254+
@extend %igx-checkbox--focused-checked-bootstrap !optional;
193255
}
194256

195257
@include m(checked) {

0 commit comments

Comments
 (0)