@@ -24,6 +24,7 @@ import {
24
24
ViewChild ,
25
25
ViewChildren ,
26
26
ViewEncapsulation ,
27
+ TemplateRef ,
27
28
} from '@angular/core' ;
28
29
import {
29
30
async ,
@@ -39,6 +40,7 @@ import {MatOption, MatOptionSelectionChange} from '@angular/material/core';
39
40
import { MatFormField , MatFormFieldModule } from '@angular/material/form-field' ;
40
41
import { By } from '@angular/platform-browser' ;
41
42
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
43
+ import { CommonModule } from '@angular/common' ;
42
44
import { EMPTY , Observable , Subject , Subscription } from 'rxjs' ;
43
45
import { map , startWith } from 'rxjs/operators' ;
44
46
@@ -69,7 +71,8 @@ describe('MatAutocomplete', () => {
69
71
MatInputModule ,
70
72
FormsModule ,
71
73
ReactiveFormsModule ,
72
- NoopAnimationsModule
74
+ NoopAnimationsModule ,
75
+ CommonModule
73
76
] ,
74
77
declarations : [ component ] ,
75
78
providers : [
@@ -538,28 +541,55 @@ describe('MatAutocomplete', () => {
538
541
} ) ) ;
539
542
540
543
it ( 'should not close the panel when clicking on the input inside shadow DOM' , fakeAsync ( ( ) => {
541
- // This test is only relevant for Shadow DOM-capable browsers.
542
- if ( ! _supportsShadowDom ( ) ) {
543
- return ;
544
- }
544
+ // This test is only relevant for Shadow DOM-capable browsers.
545
+ if ( ! _supportsShadowDom ( ) ) {
546
+ return ;
547
+ }
545
548
546
- const fixture = createComponent ( SimpleAutocompleteShadowDom ) ;
547
- fixture . detectChanges ( ) ;
548
- const input = fixture . debugElement . query ( By . css ( 'input' ) ) ! . nativeElement ;
549
+ const fixture = createComponent ( SimpleAutocompleteShadowDom ) ;
550
+ fixture . detectChanges ( ) ;
551
+ const input = fixture . debugElement . query ( By . css ( 'input' ) ) ! . nativeElement ;
549
552
550
- dispatchFakeEvent ( input , 'focusin' ) ;
551
- fixture . detectChanges ( ) ;
552
- zone . simulateZoneExit ( ) ;
553
+ dispatchFakeEvent ( input , 'focusin' ) ;
554
+ fixture . detectChanges ( ) ;
555
+ zone . simulateZoneExit ( ) ;
553
556
554
- expect ( fixture . componentInstance . trigger . panelOpen )
555
- . toBe ( true , 'Expected panel to be opened on focus.' ) ;
557
+ expect ( fixture . componentInstance . trigger . panelOpen )
558
+ . toBe ( true , 'Expected panel to be opened on focus.' ) ;
556
559
557
- input . click ( ) ;
558
- fixture . detectChanges ( ) ;
560
+ input . click ( ) ;
561
+ fixture . detectChanges ( ) ;
559
562
560
- expect ( fixture . componentInstance . trigger . panelOpen )
561
- . toBe ( true , 'Expected panel to remain opened after clicking on the input.' ) ;
562
- } ) ) ;
563
+ expect ( fixture . componentInstance . trigger . panelOpen )
564
+ . toBe ( true , 'Expected panel to remain opened after clicking on the input.' ) ;
565
+ } ) ) ;
566
+
567
+ it ( 'should not close the panel when clicking inside the shadow DOM when inserted ' +
568
+ 'through an embedded view' , fakeAsync ( ( ) => {
569
+ // This test is only relevant for Shadow DOM-capable browsers.
570
+ if ( ! _supportsShadowDom ( ) ) {
571
+ return ;
572
+ }
573
+
574
+ const fixture = createComponent ( AutocompleteInShadowDomEmbeddedView ) ;
575
+ fixture . detectChanges ( ) ;
576
+ fixture . componentInstance . currentTemplate = fixture . componentInstance . template ;
577
+ fixture . detectChanges ( ) ;
578
+
579
+ const input = fixture . nativeElement . querySelector ( 'input' ) ;
580
+ dispatchFakeEvent ( input , 'focusin' ) ;
581
+ fixture . detectChanges ( ) ;
582
+ zone . simulateZoneExit ( ) ;
583
+
584
+ expect ( overlayContainerElement . querySelector ( '.mat-autocomplete-panel' ) )
585
+ . toBeTruthy ( 'Expected panel to be opened on focus.' ) ;
586
+
587
+ input . click ( ) ;
588
+ fixture . detectChanges ( ) ;
589
+
590
+ expect ( overlayContainerElement . querySelector ( '.mat-autocomplete-panel' ) )
591
+ . toBeTruthy ( 'Expected panel to remain opened after clicking on the input.' ) ;
592
+ } ) ) ;
563
593
564
594
it ( 'should have the correct text direction in RTL' , ( ) => {
565
595
const rtlFixture = createComponent ( SimpleAutocomplete , [
@@ -2669,6 +2699,18 @@ class SimpleAutocomplete implements OnDestroy {
2669
2699
class SimpleAutocompleteShadowDom extends SimpleAutocomplete {
2670
2700
}
2671
2701
2702
+ @Component ( {
2703
+ template : `
2704
+ <ng-template #template>${ SIMPLE_AUTOCOMPLETE_TEMPLATE } </ng-template>
2705
+ <ng-container [ngTemplateOutlet]="currentTemplate"></ng-container>
2706
+ ` ,
2707
+ encapsulation : ViewEncapsulation . ShadowDom
2708
+ } )
2709
+ class AutocompleteInShadowDomEmbeddedView extends SimpleAutocomplete {
2710
+ @ViewChild ( 'template' ) template : TemplateRef < any > ;
2711
+ currentTemplate : TemplateRef < any > ;
2712
+ }
2713
+
2672
2714
@Component ( {
2673
2715
template : `
2674
2716
<mat-form-field *ngIf="isVisible">
0 commit comments