@@ -30,6 +30,7 @@ import {
30
30
ViewChildren ,
31
31
QueryList ,
32
32
ViewChild ,
33
+ ViewEncapsulation ,
33
34
} from '@angular/core' ;
34
35
import { ComponentFixture , fakeAsync , flush , inject , TestBed } from '@angular/core/testing' ;
35
36
import {
@@ -45,6 +46,7 @@ import {
45
46
import { MatRipple , ThemePalette } from '@angular/material/core' ;
46
47
import { By } from '@angular/platform-browser' ;
47
48
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
49
+ import { _supportsShadowDom } from '@angular/cdk/platform' ;
48
50
import { merge , Observable , Subject } from 'rxjs' ;
49
51
import { map , take } from 'rxjs/operators' ;
50
52
import { MatStepHeader , MatStepperModule } from './index' ;
@@ -287,6 +289,31 @@ describe('MatStepper', () => {
287
289
expect ( stepHeaderEl . focus ) . toHaveBeenCalled ( ) ;
288
290
} ) ;
289
291
292
+ it ( 'should focus next step header if focus is inside the stepper with shadow DOM' , ( ) => {
293
+ if ( ! _supportsShadowDom ( ) ) {
294
+ return ;
295
+ }
296
+
297
+ fixture . destroy ( ) ;
298
+ TestBed . resetTestingModule ( ) ;
299
+ fixture = createComponent ( SimpleMatVerticalStepperApp , [ ] , [ ] , ViewEncapsulation . ShadowDom ) ;
300
+ fixture . detectChanges ( ) ;
301
+
302
+ const stepperComponent =
303
+ fixture . debugElement . query ( By . directive ( MatStepper ) ) ! . componentInstance ;
304
+ const stepHeaderEl =
305
+ fixture . debugElement . queryAll ( By . css ( 'mat-step-header' ) ) [ 1 ] . nativeElement ;
306
+ const nextButtonNativeEl = fixture . debugElement
307
+ . queryAll ( By . directive ( MatStepperNext ) ) [ 0 ] . nativeElement ;
308
+ spyOn ( stepHeaderEl , 'focus' ) ;
309
+ nextButtonNativeEl . focus ( ) ;
310
+ nextButtonNativeEl . click ( ) ;
311
+ fixture . detectChanges ( ) ;
312
+
313
+ expect ( stepperComponent . selectedIndex ) . toBe ( 1 ) ;
314
+ expect ( stepHeaderEl . focus ) . toHaveBeenCalled ( ) ;
315
+ } ) ;
316
+
290
317
it ( 'should only be able to return to a previous step if it is editable' , ( ) => {
291
318
const stepperComponent =
292
319
fixture . debugElement . query ( By . directive ( MatStepper ) ) ! . componentInstance ;
@@ -1559,7 +1586,8 @@ function asyncValidator(minLength: number, validationTrigger: Subject<void>): As
1559
1586
1560
1587
function createComponent < T > ( component : Type < T > ,
1561
1588
providers : Provider [ ] = [ ] ,
1562
- imports : any [ ] = [ ] ) : ComponentFixture < T > {
1589
+ imports : any [ ] = [ ] ,
1590
+ encapsulation ?: ViewEncapsulation ) : ComponentFixture < T > {
1563
1591
TestBed . configureTestingModule ( {
1564
1592
imports : [
1565
1593
MatStepperModule ,
@@ -1572,8 +1600,15 @@ function createComponent<T>(component: Type<T>,
1572
1600
{ provide : Directionality , useFactory : ( ) => dir } ,
1573
1601
...providers
1574
1602
] ,
1575
- } ) . compileComponents ( ) ;
1603
+ } ) ;
1604
+
1605
+ if ( encapsulation != null ) {
1606
+ TestBed . overrideComponent ( component , {
1607
+ set : { encapsulation}
1608
+ } ) ;
1609
+ }
1576
1610
1611
+ TestBed . compileComponents ( ) ;
1577
1612
return TestBed . createComponent < T > ( component ) ;
1578
1613
}
1579
1614
0 commit comments