@@ -6,10 +6,10 @@ import {
6
6
ElementRef ,
7
7
inject ,
8
8
input ,
9
- Renderer2 ,
10
- signal ,
11
- untracked
9
+ linkedSignal ,
10
+ Renderer2
12
11
} from '@angular/core' ;
12
+ import { BooleanInput } from '@angular/cdk/coercion' ;
13
13
14
14
@Directive ( {
15
15
selector : 'input[cFormCheckInput]' ,
@@ -20,6 +20,8 @@ import {
20
20
}
21
21
} )
22
22
export class FormCheckInputDirective {
23
+ static ngAcceptInputType_indeterminate : BooleanInput ;
24
+
23
25
readonly #renderer = inject ( Renderer2 ) ;
24
26
readonly #hostElement = inject ( ElementRef ) ;
25
27
@@ -35,24 +37,23 @@ export class FormCheckInputDirective {
35
37
*/
36
38
readonly indeterminateInput = input ( false , { transform : booleanAttribute , alias : 'indeterminate' } ) ;
37
39
40
+ readonly #indeterminate = linkedSignal ( this . indeterminateInput ) ;
41
+
38
42
readonly #indeterminateEffect = effect ( ( ) => {
39
- const indeterminate = this . indeterminateInput ( ) ;
40
- if ( untracked ( this . # indeterminate) !== indeterminate ) {
43
+ if ( this . type ( ) === 'checkbox' ) {
44
+ const indeterminate = this . # indeterminate( ) ;
41
45
const htmlInputElement = this . #hostElement. nativeElement as HTMLInputElement ;
42
46
if ( indeterminate ) {
43
47
this . #renderer. setProperty ( htmlInputElement , 'checked' , false ) ;
44
48
}
45
49
this . #renderer. setProperty ( htmlInputElement , 'indeterminate' , indeterminate ) ;
46
- this . #indeterminate. set ( indeterminate ) ;
47
50
}
48
51
} ) ;
49
52
50
53
get indeterminate ( ) {
51
54
return this . #indeterminate( ) ;
52
55
}
53
56
54
- readonly #indeterminate = signal ( false ) ;
55
-
56
57
/**
57
58
* Set component validation state to valid.
58
59
* @default undefined
@@ -68,20 +69,6 @@ export class FormCheckInputDirective {
68
69
} as Record < string , boolean > ;
69
70
} ) ;
70
71
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
-
85
72
get checked ( ) : boolean {
86
73
return this . #hostElement?. nativeElement ?. checked ;
87
74
}
0 commit comments