@@ -15,8 +15,10 @@ import {Observable} from 'rxjs/Observable';
1515import { map } from 'rxjs/operator/map' ;
1616import { LEFT_ARROW , RIGHT_ARROW , ENTER , TAB } from '../keyboard/keycodes' ;
1717
18+ /** Used to generate unique ID for each stepper component. */
1819let nextId = 0 ;
1920
21+ /** Change event emitted on focus or selection changes. */
2022export class CdkStepEvent {
2123 index : number ;
2224 step : CdkStep ;
@@ -25,27 +27,18 @@ export class CdkStepEvent {
2527@Directive ( {
2628 selector : '[cdkStepper]' ,
2729 host : {
28- //'(focus)': '_onFocus()',
2930 '(keydown)' : '_onKeydown($event)'
3031 } ,
3132} )
3233export class CdkStepper {
33-
34- get focusIndex ( ) : number { return this . _focusIndex ; }
35- private _focusIndex : number = 0 ;
36-
3734 @ContentChildren ( CdkStep ) _steps : QueryList < CdkStep > ;
3835
3936 @ViewChildren ( 'stepHeader' ) _stepHeader : QueryList < ElementRef > ;
4037
41- @ViewChildren ( 'stepButton' ) _stepButton : QueryList < ElementRef > ;
42-
4338 /** The index of the currently selected step. */
4439 @Input ( )
4540 set selectedIndex ( value : number ) {
4641 this . _selectedIndex = value ;
47- //this.selectedStep = this._steps.toArray()[this._selectedIndex];
48- //this.stepEvent.emit(this._emitstepEvent());
4942 }
5043 get selectedIndex ( ) : number { return this . _selectedIndex ; }
5144 private _selectedIndex : number ;
@@ -65,45 +58,35 @@ export class CdkStepper {
6558 /** Event emitted when the selected step has changed. */
6659 @Output ( ) stepEvent = new EventEmitter < CdkStepEvent > ( ) ;
6760
61+ /** Event emitted when the focused step has changed. */
6862 @Output ( ) focusChange = new EventEmitter < CdkStepEvent > ( ) ;
6963
64+ /** The step that is currently selected. */
7065 get selectedStep ( ) : CdkStep {
7166 return this . _steps . toArray ( ) [ this . _selectedIndex ] ;
7267 }
7368 private _selectedStep : CdkStep ;
7469
70+ /** The index of the step that the focus is currently on. */
71+ get focusIndex ( ) : number { return this . _focusIndex ; }
72+ private _focusIndex : number = 0 ;
73+
7574 private _groupId : number ;
7675
7776 constructor ( ) {
7877 this . _groupId = nextId ++ ;
7978 }
80- // _keyManager: FocusKeyManager;
81-
82- //selectedIndex: number = 0;
83-
84- // ngAfterContentChecked() {
85- // this._steps.toArray()[this._selectedIndex].selected = true;
86- // }
87-
88- // constructor(private _element: ElementRef) { }
89- //
90- // ngAfterContentInit(): void {
91- // this._keyManager = new FocusKeyManager(this._steps).withWrap();
92- // }
9379
80+ /** Selects and focuses the provided step. */
9481 selectStep ( step : CdkStep ) : void {
95- //if (!step.active) { return; }
96- this . _selectedIndex = this . indexOf ( step ) ;
82+ let stepsArray = this . _steps . toArray ( ) ;
83+ this . _selectedIndex = stepsArray . indexOf ( step ) ;
9784 this . stepEvent . emit ( this . _emitStepEvent ( this . _selectedIndex ) ) ;
9885 this . _focusIndex = this . _selectedIndex ;
9986 this . _setStepFocus ( ) ;
10087 }
10188
102- indexOf ( step : CdkStep ) : number {
103- let stepsArray = this . _steps . toArray ( ) ;
104- return stepsArray . indexOf ( step ) ;
105- }
106-
89+ /** Selects and focuses the next step in list. */
10790 nextStep ( ) : void {
10891 if ( this . _selectedIndex == this . _steps . length - 1 ) { return ; }
10992 this . _selectedIndex ++ ;
@@ -112,6 +95,7 @@ export class CdkStepper {
11295 this . _setStepFocus ( ) ;
11396 }
11497
98+ /** Selects and focuses the previous step in list. */
11599 previousStep ( ) : void {
116100 if ( this . _selectedIndex == 0 ) { return ; }
117101 this . _selectedIndex -- ;
@@ -120,10 +104,12 @@ export class CdkStepper {
120104 this . _setStepFocus ( ) ;
121105 }
122106
107+ /** Returns a unique id for each step label element. */
123108 _getStepLabelId ( i : number ) : string {
124109 return `mat-step-label-${ this . _groupId } -${ i } ` ;
125110 }
126111
112+ /** Returns a unique id for each step content element. */
127113 _getStepContentId ( i : number ) : string {
128114 return `mat-step-content-${ this . _groupId } -${ i } ` ;
129115 }
@@ -133,12 +119,9 @@ export class CdkStepper {
133119 event . index = index ;
134120 event . step = this . _steps . toArray ( ) [ this . _selectedIndex ] ;
135121 this . _selectedStep = event . step ;
136- //this._focusIndex = this._selectedIndex;
137- //this._setStepFocus();
138122 return event ;
139123 }
140124
141-
142125 _onKeydown ( event : KeyboardEvent ) {
143126 switch ( event . keyCode ) {
144127 case RIGHT_ARROW :
@@ -158,16 +141,13 @@ export class CdkStepper {
158141 this . _emitStepEvent ( this . _selectedIndex ) ;
159142 break ;
160143 }
161- if ( event . keyCode != TAB ) event . preventDefault ( ) ;
144+ if ( event . keyCode != TAB ) {
145+ event . preventDefault ( ) ;
146+ }
162147 }
163148
164149 _setStepFocus ( ) {
165150 this . _stepHeader . toArray ( ) [ this . _focusIndex ] . nativeElement . focus ( ) ;
166151 this . focusChange . emit ( this . _emitStepEvent ( this . _selectedIndex ) ) ;
167152 }
168-
169- // _onFocus() {
170- // //this._keyManager.setFirstItemActive();
171- // this._element.nativeElement.focus();
172- // }
173153}
0 commit comments