Skip to content

Commit 918b503

Browse files
committed
Minor code clean up based on review.
1 parent 26f73f9 commit 918b503

File tree

6 files changed

+29
-27
lines changed

6 files changed

+29
-27
lines changed

src/cdk/stepper/step-label.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {Directive, TemplateRef} from '@angular/core';
1010

1111
@Directive({
12-
selector: 'cdkStepLabel',
12+
selector: 'cdk-step-label',
1313
})
1414
export class CdkStepLabel {
1515
constructor(public template: TemplateRef<any>) { }

src/cdk/stepper/stepper.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ let nextId = 0;
3232
/** Change event emitted on selection changes. */
3333
export class CdkStepperSelectionEvent {
3434
/** The index of the step that is newly selected during this change event. */
35-
newIndex: number;
35+
selectedIndex: number;
3636

3737
/** The index of the step that was previously selected. */
38-
oldIndex: number;
38+
previouslySelectedIndex: number;
3939

4040
/** The new step component that is selected ruing this change event. */
41-
newStep: CdkStep;
41+
selectedStep: CdkStep;
4242

4343
/** The step component that was previously selected. */
44-
oldStep: CdkStep;
44+
previouslySelectedStep: CdkStep;
4545
}
4646

4747
@Component({
@@ -70,7 +70,7 @@ export class CdkStep {
7070
@Directive({
7171
selector: 'cdk-stepper',
7272
host: {
73-
'(focus)': '_setStepfocused()',
73+
'(focus)': '_setStepFocused()',
7474
'(keydown)': '_onKeydown($event)',
7575
},
7676
})
@@ -79,14 +79,15 @@ export class CdkStepper {
7979
@ContentChildren(CdkStep) _steps: QueryList<CdkStep>;
8080

8181
/** The list of step headers of the steps in the stepper. */
82-
@ViewChildren('stepHeader') _stepHeader: QueryList<ElementRef>;
82+
_stepHeader: QueryList<ElementRef>;
8383

8484
/** The index of the selected step. */
8585
get selectedIndex() { return this._selectedIndex; }
8686
set selectedIndex(index: number) {
87-
if (this._selectedIndex == index) { return; }
88-
this._emitStepperSelectionEvent(index);
89-
this._setStepFocused(this._selectedIndex);
87+
if (this._selectedIndex != index) {
88+
this._emitStepperSelectionEvent(index);
89+
this._setStepFocused(this._selectedIndex);
90+
}
9091
}
9192
private _selectedIndex: number = 0;
9293

@@ -113,14 +114,12 @@ export class CdkStepper {
113114

114115
/** Selects and focuses the next step in list. */
115116
next(): void {
116-
if (this._selectedIndex == this._steps.length - 1) { return; }
117-
this.selectedIndex++;
117+
this.selectedIndex = Math.min(this._selectedIndex + 1, this._steps.length - 1);
118118
}
119119

120120
/** Selects and focuses the previous step in list. */
121121
previous(): void {
122-
if (this._selectedIndex == 0) { return; }
123-
this.selectedIndex--;
122+
this.selectedIndex = Math.max(this._selectedIndex - 1, 0);
124123
}
125124

126125
/** Returns a unique id for each step label element. */
@@ -134,14 +133,14 @@ export class CdkStepper {
134133
}
135134

136135
private _emitStepperSelectionEvent(newIndex: number): void {
137-
const event = new CdkStepperSelectionEvent();
138-
event.oldIndex = this._selectedIndex;
139-
event.newIndex = newIndex;
140-
let stepsArray = this._steps.toArray();
141-
event.oldStep = stepsArray[this._selectedIndex];
142-
event.newStep = stepsArray[newIndex];
136+
const stepsArray = this._steps.toArray();
137+
this.selectionChange.emit({
138+
selectedIndex: newIndex,
139+
previouslySelectedIndex: this._selectedIndex,
140+
selectedStep: stepsArray[newIndex],
141+
previouslySelectedStep: stepsArray[this._selectedIndex],
142+
});
143143
this._selectedIndex = newIndex;
144-
this.selectionChange.emit(event);
145144
}
146145

147146
_onKeydown(event: KeyboardEvent) {

src/lib/stepper/stepper-horizontal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<div class="mat-stepper-label">
1414
<!-- If there is a label template, use it. -->
15-
<ng-container *ngIf="step.stepLabel"[ngTemplateOutlet]="step.stepLabel.template">
15+
<ng-container *ngIf="step.stepLabel" [ngTemplateOutlet]="step.stepLabel.template">
1616
</ng-container>
1717
<!-- It there is no label template, fall back to the text label. -->
1818
<div *ngIf="!step.stepLabel">{{step.label}}</div>

src/lib/stepper/stepper-horizontal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Component, ContentChildren, forwardRef, QueryList} from '@angular/core';
9+
import {Component, ContentChildren, QueryList} from '@angular/core';
1010
import {MdStep} from './step';
1111
import {MdStepper} from './stepper';
1212

@@ -20,7 +20,7 @@ import {MdStepper} from './stepper';
2020
'class': 'mat-stepper-horizontal',
2121
'role': 'tablist',
2222
},
23-
providers: [{ provide: MdStepper, useExisting: forwardRef(() => MdHorizontalStepper) }]
23+
providers: [{ provide: MdStepper, useExisting: MdHorizontalStepper }]
2424
})
2525
export class MdHorizontalStepper extends MdStepper {
2626
/** Steps that the horizontal stepper holds. */

src/lib/stepper/stepper-vertical.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Component, ContentChildren, forwardRef, QueryList} from '@angular/core';
9+
import {Component, ContentChildren, QueryList} from '@angular/core';
1010
import {MdStep} from './step';
1111
import {MdStepper} from './stepper';
1212

@@ -20,7 +20,7 @@ import {MdStepper} from './stepper';
2020
'class': 'mat-stepper-vertical',
2121
'role': 'tablist',
2222
},
23-
providers: [{ provide: MdStepper, useExisting: forwardRef(() => MdVerticalStepper) }]
23+
providers: [{ provide: MdStepper, useExisting: MdVerticalStepper }]
2424
})
2525
export class MdVerticalStepper extends MdStepper {
2626
/** Steps that the vertical stepper holds. */

src/lib/stepper/stepper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
*/
88

99
import {CdkStepper} from '@angular/cdk';
10+
import {ElementRef, QueryList, ViewChildren} from '@angular/core';
1011

11-
export class MdStepper extends CdkStepper { }
12+
export class MdStepper extends CdkStepper {
13+
@ViewChildren('stepHeader') _stepHeader: QueryList<ElementRef>;
14+
}

0 commit comments

Comments
 (0)