1
1
import {
2
2
ViewChild , HostBinding , ElementRef , HostListener , Input , ContentChildren , QueryList ,
3
- AfterContentInit , TemplateRef , ViewContainerRef , ContentChild , EventEmitter , Output , OnDestroy
3
+ TemplateRef , ViewContainerRef , ContentChild , EventEmitter , Output , OnDestroy , AfterViewInit
4
4
} from "@angular/core" ;
5
5
import { Subscription } from "rxjs" ;
6
6
import { DropdownService , SuiDropdownMenu } from "../../dropdown/internal" ;
@@ -16,11 +16,11 @@ export interface IOptionContext<T> extends ITemplateRefContext<T> {
16
16
17
17
// We use generic type T to specify the type of the options we are working with,
18
18
// and U to specify the type of the property of the option used as the value.
19
- export abstract class SuiSelectBase < T , U > implements AfterContentInit , OnDestroy {
19
+ export abstract class SuiSelectBase < T , U > implements AfterViewInit , OnDestroy {
20
20
public dropdownService :DropdownService ;
21
21
public searchService :SearchService < T , U > ;
22
22
23
- @ViewChild ( SuiDropdownMenu , { static : true } )
23
+ @ViewChild ( SuiDropdownMenu )
24
24
protected _menu :SuiDropdownMenu ;
25
25
26
26
// Keep track of all of the rendered select options. (Rendered by the user using *ngFor).
@@ -42,7 +42,10 @@ export abstract class SuiSelectBase<T, U> implements AfterContentInit, OnDestroy
42
42
43
43
@HostBinding ( "class.visible" )
44
44
public get isVisible ( ) :boolean {
45
- return this . _menu . isVisible ;
45
+ if ( this . _menu ) {
46
+ return this . _menu ?. isVisible ;
47
+ }
48
+ return false ;
46
49
}
47
50
48
51
@Input ( )
@@ -245,7 +248,7 @@ export abstract class SuiSelectBase<T, U> implements AfterContentInit, OnDestroy
245
248
this . hasClasses = true ;
246
249
}
247
250
248
- public ngAfterContentInit ( ) :void {
251
+ public ngAfterViewInit ( ) :void {
249
252
this . _menu . service = this . dropdownService ;
250
253
// We manually specify the menu items to the menu because the @ContentChildren doesn't pick up our dynamically rendered items.
251
254
this . _menu . items = this . _renderedOptions ;
@@ -286,7 +289,7 @@ export abstract class SuiSelectBase<T, U> implements AfterContentInit, OnDestroy
286
289
// The search delay is set to the transition duration to ensure results
287
290
// aren't rendered as the select closes as that causes a sudden flash.
288
291
if ( delayed ) {
289
- this . searchService . searchDelay = this . _menu . menuTransitionDuration ;
292
+ this . searchService . searchDelay = this . _menu ? .menuTransitionDuration ;
290
293
this . searchService . updateQueryDelayed ( "" ) ;
291
294
} else {
292
295
this . searchService . updateQuery ( "" ) ;
0 commit comments