22// Licensed under the MIT License.
33
44import { InputRendererOptions , JsxRenderFunc , ReactWrapperComponent } from '@angular-react/core' ;
5- import { ChangeDetectorRef , ElementRef , EventEmitter , Input , NgZone , OnInit , Output , Renderer2 } from '@angular/core' ;
5+ import {
6+ ChangeDetectorRef ,
7+ ElementRef ,
8+ EventEmitter ,
9+ Input ,
10+ NgZone ,
11+ OnInit ,
12+ Output ,
13+ Renderer2 ,
14+ ContentChild ,
15+ AfterContentInit ,
16+ } from '@angular/core' ;
617import { IComboBox , IComboBoxOption , IComboBoxProps } from 'office-ui-fabric-react/lib/ComboBox' ;
18+ import { ComboBoxOptionDirective } from './directives/combo-box-option.directive' ;
19+ import { ComboBoxOptionsDirective } from './directives/combo-box-options.directive' ;
20+
21+ export abstract class FabBaseComboBoxComponent extends ReactWrapperComponent < IComboBoxProps >
22+ implements OnInit , AfterContentInit {
23+ @ContentChild ( ComboBoxOptionDirective ) readonly optionsDirective ?: ComboBoxOptionDirective ;
724
8- export abstract class FabBaseComboBoxComponent extends ReactWrapperComponent < IComboBoxProps > implements OnInit {
925 @Input ( ) componentRef ?: IComboBoxProps [ 'componentRef' ] ;
1026 @Input ( ) options : IComboBoxProps [ 'options' ] ;
1127 @Input ( ) allowFreeform ?: IComboBoxProps [ 'allowFreeform' ] ;
@@ -49,6 +65,8 @@ export abstract class FabBaseComboBoxComponent extends ReactWrapperComponent<ICo
4965 @Output ( ) readonly onMenuDismissed = new EventEmitter < void > ( ) ;
5066 @Output ( ) readonly onScrollToItem = new EventEmitter < { itemIndex : number } > ( ) ;
5167
68+ @ContentChild ( ComboBoxOptionsDirective ) readonly comboBoxOptionsDirective ?: ComboBoxOptionsDirective ;
69+
5270 onRenderLowerContent : ( props ?: IComboBoxProps , defaultRender ?: JsxRenderFunc < IComboBoxProps > ) => JSX . Element ;
5371
5472 constructor ( elementRef : ElementRef , changeDetectorRef : ChangeDetectorRef , renderer : Renderer2 , ngZone : NgZone ) {
@@ -65,6 +83,13 @@ export abstract class FabBaseComboBoxComponent extends ReactWrapperComponent<ICo
6583 this . onRenderLowerContent = this . createRenderPropHandler ( this . renderLowerContent ) ;
6684 }
6785
86+ ngAfterContentInit ( ) {
87+ if ( this . comboBoxOptionsDirective ) {
88+ this . _initDirective ( this . comboBoxOptionsDirective ) ;
89+ }
90+ super . ngAfterContentInit ( ) ;
91+ }
92+
6893 onItemClickHandler ( event : React . FormEvent < IComboBox > , option ?: IComboBoxOption , index ?: number ) {
6994 this . onItemClick . emit ( {
7095 event : event . nativeEvent ,
@@ -95,4 +120,9 @@ export abstract class FabBaseComboBoxComponent extends ReactWrapperComponent<ICo
95120 itemIndex,
96121 } ) ;
97122 }
123+
124+ private _initDirective ( directive : ComboBoxOptionsDirective ) {
125+ this . options = directive . items ;
126+ this . markForCheck ( ) ;
127+ }
98128}
0 commit comments