1
1
import { Directionality } from '@angular/cdk/bidi' ;
2
- import { ENTER , LEFT_ARROW , RIGHT_ARROW , SPACE } from '@angular/cdk/keycodes' ;
2
+ import { ENTER , LEFT_ARROW , RIGHT_ARROW , UP_ARROW , DOWN_ARROW , SPACE } from '@angular/cdk/keycodes' ;
3
3
import { dispatchKeyboardEvent } from '@angular/cdk/testing' ;
4
4
import { Component , DebugElement } from '@angular/core' ;
5
5
import { async , ComponentFixture , TestBed , inject } from '@angular/core/testing' ;
6
6
import { AbstractControl , AsyncValidatorFn , FormControl , FormGroup , ReactiveFormsModule ,
7
7
ValidationErrors , Validators } from '@angular/forms' ;
8
8
import { By } from '@angular/platform-browser' ;
9
9
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
10
+ import { StepperOrientation } from '@angular/cdk/stepper' ;
10
11
import { map } from 'rxjs/operators/map' ;
11
12
import { take } from 'rxjs/operators/take' ;
12
13
import { Observable } from 'rxjs/Observable' ;
@@ -18,7 +19,7 @@ import {MatStepperIntl} from './stepper-intl';
18
19
19
20
const VALID_REGEX = / v a l i d / ;
20
21
21
- describe ( 'MatHorizontalStepper' , ( ) => {
22
+ fdescribe ( 'MatHorizontalStepper' , ( ) => {
22
23
let dir = 'ltr' ;
23
24
24
25
beforeEach ( async ( ( ) => {
@@ -87,9 +88,9 @@ describe('MatHorizontalStepper', () => {
87
88
assertCorrectStepAnimationDirection ( fixture ) ;
88
89
} ) ;
89
90
90
- it ( 'should support keyboard events to move and select focus' , ( ) => {
91
+ it ( 'should support using the left/right arrows to move focus' , ( ) => {
91
92
let stepHeaders = fixture . debugElement . queryAll ( By . css ( '.mat-horizontal-stepper-header' ) ) ;
92
- assertCorrectKeyboardInteraction ( fixture , stepHeaders ) ;
93
+ assertCorrectKeyboardInteraction ( fixture , stepHeaders , 'horizontal' ) ;
93
94
} ) ;
94
95
95
96
it ( 'should not set focus on header of selected step if header is not clicked' , ( ) => {
@@ -202,7 +203,7 @@ describe('MatHorizontalStepper', () => {
202
203
} ) ;
203
204
} ) ;
204
205
205
- describe ( 'MatVerticalStepper' , ( ) => {
206
+ fdescribe ( 'MatVerticalStepper' , ( ) => {
206
207
let dir = 'ltr' ;
207
208
208
209
beforeEach ( async ( ( ) => {
@@ -271,9 +272,14 @@ describe('MatVerticalStepper', () => {
271
272
assertCorrectStepAnimationDirection ( fixture ) ;
272
273
} ) ;
273
274
274
- it ( 'should support keyboard events to move and select focus' , ( ) => {
275
+ it ( 'should support using the left/right arrows to move focus' , ( ) => {
275
276
let stepHeaders = fixture . debugElement . queryAll ( By . css ( '.mat-vertical-stepper-header' ) ) ;
276
- assertCorrectKeyboardInteraction ( fixture , stepHeaders ) ;
277
+ assertCorrectKeyboardInteraction ( fixture , stepHeaders , 'horizontal' ) ;
278
+ } ) ;
279
+
280
+ it ( 'should support using the up/down arrows to move focus' , ( ) => {
281
+ let stepHeaders = fixture . debugElement . queryAll ( By . css ( '.mat-vertical-stepper-header' ) ) ;
282
+ assertCorrectKeyboardInteraction ( fixture , stepHeaders , 'vertical' ) ;
277
283
} ) ;
278
284
279
285
it ( 'should not set focus on header of selected step if header is not clicked' , ( ) => {
@@ -516,20 +522,23 @@ function assertCorrectStepAnimationDirection(fixture: ComponentFixture<any>, rtl
516
522
517
523
/** Asserts that keyboard interaction works correctly. */
518
524
function assertCorrectKeyboardInteraction ( fixture : ComponentFixture < any > ,
519
- stepHeaders : DebugElement [ ] ) {
525
+ stepHeaders : DebugElement [ ] ,
526
+ orientation : StepperOrientation ) {
520
527
let stepperComponent = fixture . debugElement . query ( By . directive ( MatStepper ) ) . componentInstance ;
528
+ let nextKey = orientation === 'vertical' ? DOWN_ARROW : RIGHT_ARROW ;
529
+ let prevKey = orientation === 'vertical' ? UP_ARROW : LEFT_ARROW ;
521
530
522
531
expect ( stepperComponent . _focusIndex ) . toBe ( 0 ) ;
523
532
expect ( stepperComponent . selectedIndex ) . toBe ( 0 ) ;
524
533
525
534
let stepHeaderEl = stepHeaders [ 0 ] . nativeElement ;
526
- dispatchKeyboardEvent ( stepHeaderEl , 'keydown' , RIGHT_ARROW ) ;
535
+ dispatchKeyboardEvent ( stepHeaderEl , 'keydown' , nextKey ) ;
527
536
fixture . detectChanges ( ) ;
528
537
529
538
expect ( stepperComponent . _focusIndex )
530
- . toBe ( 1 , 'Expected index of focused step to increase by 1 after RIGHT_ARROW event .' ) ;
539
+ . toBe ( 1 , 'Expected index of focused step to increase by 1 after pressing the next key .' ) ;
531
540
expect ( stepperComponent . selectedIndex )
532
- . toBe ( 0 , 'Expected index of selected step to remain unchanged after RIGHT_ARROW event .' ) ;
541
+ . toBe ( 0 , 'Expected index of selected step to remain unchanged after pressing the next key .' ) ;
533
542
534
543
stepHeaderEl = stepHeaders [ 1 ] . nativeElement ;
535
544
dispatchKeyboardEvent ( stepHeaderEl , 'keydown' , ENTER ) ;
@@ -542,26 +551,25 @@ function assertCorrectKeyboardInteraction(fixture: ComponentFixture<any>,
542
551
'Expected index of selected step to change to index of focused step after ENTER event.' ) ;
543
552
544
553
stepHeaderEl = stepHeaders [ 1 ] . nativeElement ;
545
- dispatchKeyboardEvent ( stepHeaderEl , 'keydown' , LEFT_ARROW ) ;
554
+ dispatchKeyboardEvent ( stepHeaderEl , 'keydown' , prevKey ) ;
546
555
fixture . detectChanges ( ) ;
547
556
548
557
expect ( stepperComponent . _focusIndex )
549
- . toBe ( 0 , 'Expected index of focused step to decrease by 1 after LEFT_ARROW event .' ) ;
550
- expect ( stepperComponent . selectedIndex )
551
- . toBe ( 1 , 'Expected index of selected step to remain unchanged after LEFT_ARROW event .' ) ;
558
+ . toBe ( 0 , 'Expected index of focused step to decrease by 1 after pressing the previous key .' ) ;
559
+ expect ( stepperComponent . selectedIndex ) . toBe ( 1 ,
560
+ 'Expected index of selected step to remain unchanged after pressing the previous key .' ) ;
552
561
553
562
// When the focus is on the last step and right arrow key is pressed, the focus should cycle
554
563
// through to the first step.
555
564
stepperComponent . _focusIndex = 2 ;
556
565
stepHeaderEl = stepHeaders [ 2 ] . nativeElement ;
557
- dispatchKeyboardEvent ( stepHeaderEl , 'keydown' , RIGHT_ARROW ) ;
566
+ dispatchKeyboardEvent ( stepHeaderEl , 'keydown' , nextKey ) ;
558
567
fixture . detectChanges ( ) ;
559
568
560
- expect ( stepperComponent . _focusIndex )
561
- . toBe ( 0 ,
562
- 'Expected index of focused step to cycle through to index 0 after RIGHT_ARROW event.' ) ;
569
+ expect ( stepperComponent . _focusIndex ) . toBe ( 0 ,
570
+ 'Expected index of focused step to cycle through to index 0 after pressing the next key.' ) ;
563
571
expect ( stepperComponent . selectedIndex )
564
- . toBe ( 1 , 'Expected index of selected step to remain unchanged after RIGHT_ARROW event .' ) ;
572
+ . toBe ( 1 , 'Expected index of selected step to remain unchanged after pressing the next key .' ) ;
565
573
566
574
stepHeaderEl = stepHeaders [ 0 ] . nativeElement ;
567
575
dispatchKeyboardEvent ( stepHeaderEl , 'keydown' , SPACE ) ;
0 commit comments