1- import { ElementRef , EventEmitter , Inject , LOCALE_ID , Optional , Input , Directive , Output } from '@angular/core' ;
1+ import {
2+ AfterViewInit , ContentChildren , Directive , ElementRef , EventEmitter ,
3+ Inject , Input , LOCALE_ID , OnDestroy , Optional , Output , QueryList
4+ } from '@angular/core' ;
5+ import { merge , Subject } from 'rxjs' ;
6+ import { takeUntil } from 'rxjs/operators' ;
27import { DisplayDensityBase , DisplayDensityToken , IDisplayDensityOptions } from '../core/density' ;
38import { EditorProvider } from '../core/edit-provider' ;
4- import { PickerInteractionMode } from './types' ;
59import { IToggleView } from '../core/navigation' ;
610import { IBaseCancelableBrowserEventArgs , IBaseEventArgs } from '../core/utils' ;
711import { DateRange } from '../date-range-picker/public_api' ;
812import { IgxOverlayOutletDirective } from '../directives/toggle/toggle.directive' ;
913import { IgxInputGroupType , IGX_INPUT_GROUP_TYPE } from '../input-group/public_api' ;
1014import { OverlaySettings } from '../services/overlay/utilities' ;
15+ import { IgxPickerToggleComponent } from './picker-icons.common' ;
16+ import { PickerInteractionMode } from './types' ;
1117
1218@Directive ( )
13- export abstract class PickerBaseDirective extends DisplayDensityBase implements IToggleView , EditorProvider {
19+ export abstract class PickerBaseDirective extends DisplayDensityBase implements IToggleView , EditorProvider , AfterViewInit , OnDestroy {
1420 /**
1521 * The editor's input mask.
1622 *
@@ -193,6 +199,10 @@ export abstract class PickerBaseDirective extends DisplayDensityBase implements
193199 @Output ( )
194200 public closed = new EventEmitter < IBaseEventArgs > ( ) ;
195201
202+ /** @hidden @internal */
203+ @ContentChildren ( IgxPickerToggleComponent , { descendants : true } )
204+ public toggleComponents : QueryList < IgxPickerToggleComponent > ;
205+
196206 protected _collapsed = true ;
197207 protected _type : IgxInputGroupType ;
198208 protected _minValue : Date | string ;
@@ -215,6 +225,8 @@ export abstract class PickerBaseDirective extends DisplayDensityBase implements
215225 return this . mode === PickerInteractionMode . DropDown ;
216226 }
217227
228+ protected _destroy$ = new Subject ( ) ;
229+
218230 public abstract valueChange : EventEmitter < string | Date | DateRange | null > ;
219231
220232 constructor ( public element : ElementRef ,
@@ -225,6 +237,28 @@ export abstract class PickerBaseDirective extends DisplayDensityBase implements
225237 this . locale = this . locale || this . _localeId ;
226238 }
227239
240+ /** @hidden @internal */
241+ public ngAfterViewInit ( ) : void {
242+ this . subToIconsClicked ( this . toggleComponents , ( ) => this . open ( ) ) ;
243+ this . toggleComponents . changes . pipe ( takeUntil ( this . _destroy$ ) )
244+ . subscribe ( ( ) => this . subToIconsClicked ( this . toggleComponents , ( ) => this . open ( ) ) ) ;
245+ }
246+
247+ /** @hidden @internal */
248+ public ngOnDestroy ( ) : void {
249+ this . _destroy$ . next ( ) ;
250+ this . _destroy$ . complete ( ) ;
251+ }
252+
253+ /** Subscribes to the click events of toggle/clear icons in a query */
254+ protected subToIconsClicked ( components : QueryList < IgxPickerToggleComponent > , next : ( ) => any ) {
255+ components . forEach ( toggle => {
256+ toggle . clicked
257+ . pipe ( takeUntil ( merge ( components . changes , this . _destroy$ ) ) )
258+ . subscribe ( next ) ;
259+ } ) ;
260+ } ;
261+
228262 public abstract select ( value : Date | DateRange | string ) : void ;
229263 public abstract open ( settings ?: OverlaySettings ) : void ;
230264 public abstract toggle ( settings ?: OverlaySettings ) : void ;
0 commit comments