@@ -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} )
2222export 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 }
0 commit comments