11import { DestroyRef , Directive , ElementRef , HostBinding , HostListener , inject , OnInit } from '@angular/core' ;
22import { takeUntilDestroyed , toSignal } from '@angular/core/rxjs-interop' ;
3+ import { ɵeffectWithDeps } from '@lucca-front/ng/core' ;
34import { ILuOptionContext , LU_OPTION_CONTEXT } from '@lucca-front/ng/core-select' ;
5+ import { InputDirective } from '@lucca-front/ng/form-field' ;
46import { of } from 'rxjs' ;
57import { startWith , switchMap } from 'rxjs/operators' ;
68import { LuMultiSelectInputComponent } from '../input' ;
7- import { InputDirective } from '@lucca-front/ng/form-field ' ;
9+ import { MULTI_SELECT_WITH_SELECT_ALL_CONTEXT } from '../input/select-all/select-all.models ' ;
810
911@Directive ( {
1012 selector : '[luMultiSelectDisplayerInput]' ,
@@ -19,6 +21,7 @@ import { InputDirective } from '@lucca-front/ng/form-field';
1921} )
2022export class LuMultiSelectDisplayerInputDirective < T > implements OnInit {
2123 select = inject < LuMultiSelectInputComponent < T > > ( LuMultiSelectInputComponent ) ;
24+ readonly selectAllContext = inject ( MULTI_SELECT_WITH_SELECT_ALL_CONTEXT , { optional : true } ) ;
2225
2326 context = inject < ILuOptionContext < T [ ] > > ( LU_OPTION_CONTEXT ) ;
2427
@@ -76,16 +79,30 @@ export class LuMultiSelectDisplayerInputDirective<T> implements OnInit {
7679 ) ,
7780 ) ;
7881
82+ constructor ( ) {
83+ if ( this . selectAllContext ) {
84+ ɵeffectWithDeps ( [ this . selectAllContext . mode ] , ( mode ) => {
85+ if ( mode === 'all' ) {
86+ this . #clearText( ) ;
87+ }
88+ } ) ;
89+ }
90+ }
91+
7992 ngOnInit ( ) : void {
8093 this . select . focusInput$ . pipe ( takeUntilDestroyed ( this . destroyRef ) ) . subscribe ( ( data ?: { keepClue : boolean } ) => {
8194 if ( ! data ?. keepClue ) {
82- this . elementRef . nativeElement . value = '' ;
83- this . select . clueChanged ( '' ) ;
95+ this . #clearText( ) ;
8496 }
8597 this . elementRef . nativeElement . focus ( ) ;
8698 } ) ;
8799 this . select . emptyClue$ . pipe ( takeUntilDestroyed ( this . destroyRef ) ) . subscribe ( ( ) => {
88100 this . elementRef . nativeElement . value = '' ;
89101 } ) ;
90102 }
103+
104+ #clearText( ) {
105+ this . elementRef . nativeElement . value = '' ;
106+ this . select . clueChanged ( '' ) ;
107+ }
91108}
0 commit comments