Skip to content

Commit 3e85145

Browse files
committed
fix(form-check-input): checked prop overwrites checked from writeValue in ReactiveForms
1 parent 45189c1 commit 3e85145

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
---
44

5+
#### `5.4.8` next
6+
7+
- fix(form-check-input): checked prop overwrites checked from writeValue in ReactiveForms
8+
9+
---
10+
511
#### `5.4.7`
612

713
- fix(avatar): default size should be '' not `md`

projects/coreui-angular/src/lib/form/form-check/form-check-input.directive.ts

+9-22
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
ElementRef,
77
inject,
88
input,
9-
Renderer2,
10-
signal,
11-
untracked
9+
linkedSignal,
10+
Renderer2
1211
} from '@angular/core';
12+
import { BooleanInput } from '@angular/cdk/coercion';
1313

1414
@Directive({
1515
selector: 'input[cFormCheckInput]',
@@ -20,6 +20,8 @@ import {
2020
}
2121
})
2222
export class FormCheckInputDirective {
23+
static ngAcceptInputType_indeterminate: BooleanInput;
24+
2325
readonly #renderer = inject(Renderer2);
2426
readonly #hostElement = inject(ElementRef);
2527

@@ -35,24 +37,23 @@ export class FormCheckInputDirective {
3537
*/
3638
readonly indeterminateInput = input(false, { transform: booleanAttribute, alias: 'indeterminate' });
3739

40+
readonly #indeterminate = linkedSignal(this.indeterminateInput);
41+
3842
readonly #indeterminateEffect = effect(() => {
39-
const indeterminate = this.indeterminateInput();
40-
if (untracked(this.#indeterminate) !== indeterminate) {
43+
if (this.type() === 'checkbox') {
44+
const indeterminate = this.#indeterminate();
4145
const htmlInputElement = this.#hostElement.nativeElement as HTMLInputElement;
4246
if (indeterminate) {
4347
this.#renderer.setProperty(htmlInputElement, 'checked', false);
4448
}
4549
this.#renderer.setProperty(htmlInputElement, 'indeterminate', indeterminate);
46-
this.#indeterminate.set(indeterminate);
4750
}
4851
});
4952

5053
get indeterminate() {
5154
return this.#indeterminate();
5255
}
5356

54-
readonly #indeterminate = signal(false);
55-
5657
/**
5758
* Set component validation state to valid.
5859
* @default undefined
@@ -68,20 +69,6 @@ export class FormCheckInputDirective {
6869
} as Record<string, boolean>;
6970
});
7071

71-
/**
72-
* Set component checked state.
73-
* @default false
74-
*/
75-
readonly checkedInput = input(false, { transform: booleanAttribute, alias: 'checked' });
76-
77-
readonly #checkedEffect = effect(() => {
78-
const checked = this.checkedInput();
79-
const htmlInputElement = this.#hostElement?.nativeElement as HTMLInputElement;
80-
if (htmlInputElement) {
81-
this.#renderer.setProperty(htmlInputElement, 'checked', checked);
82-
}
83-
});
84-
8572
get checked(): boolean {
8673
return this.#hostElement?.nativeElement?.checked;
8774
}

projects/coreui-angular/src/lib/form/form-check/form-check.component.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { BooleanInput } from '@angular/cdk/coercion';
12
import { booleanAttribute, Component, computed, contentChild, input } from '@angular/core';
2-
33
import { FormCheckLabelDirective } from './form-check-label.directive';
44

55
@Component({
@@ -9,6 +9,10 @@ import { FormCheckLabelDirective } from './form-check-label.directive';
99
host: { '[class]': 'hostClasses()' }
1010
})
1111
export class FormCheckComponent {
12+
static ngAcceptInputType_inline: BooleanInput;
13+
static ngAcceptInputType_reverse: BooleanInput;
14+
static ngAcceptInputType_switch: BooleanInput;
15+
1216
/**
1317
* Group checkboxes or radios on the same horizontal row.
1418
* @default false
@@ -30,15 +34,13 @@ export class FormCheckComponent {
3034

3135
/**
3236
* Render a toggle switch on for checkbox.
33-
* @type boolean
37+
* @returns boolean
3438
* @default false
3539
*/
3640
readonly switch = input(false, { transform: booleanAttribute });
3741

3842
readonly formCheckLabel = contentChild(FormCheckLabelDirective);
3943

40-
readonly formCheckClass = computed(() => !!this.formCheckLabel());
41-
4244
readonly hostClasses = computed(() => {
4345
const sizing = this.sizing();
4446
const isSwitch = this.switch();

0 commit comments

Comments
 (0)