Skip to content

Commit 36ad2cc

Browse files
committed
Changes made based on the review
1 parent f417435 commit 36ad2cc

File tree

11 files changed

+69
-85
lines changed

11 files changed

+69
-85
lines changed

src/cdk/stepper/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {CommonModule} from '@angular/common';
1212
import {CdkStep} from './step';
1313
import {CdkStepLabel} from './step-label';
1414
import {PortalModule} from '../portal';
15+
1516
@NgModule({
1617
imports: [CommonModule, PortalModule],
1718
exports: [CdkStep, CdkStepper, CdkStepLabel],

src/cdk/stepper/step-label.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import {Directive, TemplateRef, ViewContainerRef} from '@angular/core';
1010
import {TemplatePortalDirective} from '../portal';
11+
1112
@Directive({
1213
selector: '[cdk-step-label]',
1314
})

src/cdk/stepper/step.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,42 @@
77
*/
88

99
import {
10-
Component, ContentChild, Directive, Input, OnInit, TemplateRef, ViewChild,
11-
ViewContainerRef
10+
Component, ContentChild, Input, TemplateRef, ViewChild
1211
} from '@angular/core';
1312
import {CdkStepLabel} from './step-label';
13+
import {coerceBooleanProperty} from '../coercion/boolean-property';
1414

1515
@Component({
1616
selector: '[cdk-step]',
1717
templateUrl: 'step.html',
1818
})
1919
export class CdkStep {
20+
/** Template for step label if it exists. */
2021
@ContentChild(CdkStepLabel) stepLabel: CdkStepLabel;
22+
23+
/** Template for step content. */
2124
@ViewChild(TemplateRef) content: TemplateRef<any>;
2225

2326
/** Label of the step. */
2427
@Input()
2528
label: string;
2629

2730
/** Whether the step is optional or not. */
28-
@Input() optional: boolean = false;
31+
@Input()
32+
get optional() { return this._optional; }
33+
set optional(value: any) {
34+
this._optional = coerceBooleanProperty(value);
35+
}
36+
private _optional: boolean = false;
2937

3038
/** Whether the step is editable or not. */
31-
@Input() editable: boolean = true;
32-
33-
/** Whether the step is the last one in the list. */
34-
isLast: boolean = false;
35-
36-
// /** Whether the step is active. */
37-
// get active() { return this._active; }
38-
// set active(value: boolean) {
39-
// this._active = value;
40-
// }
41-
// private _active: boolean = false;
42-
43-
/** Whether the step has been selected. */
44-
get selected(): boolean { return this._selected; }
45-
set selected(value: boolean) {
46-
this._selected = value;
39+
@Input()
40+
get editable() { return this._editable; }
41+
set editable(value: any) {
42+
this._editable = coerceBooleanProperty(value);
4743
}
48-
private _selected: boolean = false;
44+
private _editable: boolean = true;
4945

50-
/** Whether the step has been completed. */
51-
get completed() { return this._completed; }
52-
set completed(value: boolean) {
53-
this._completed = value;
54-
}
55-
private _completed: boolean = false;
46+
/** Whether the step is the last one in the list. */
47+
_isLast: boolean = false;
5648
}

src/cdk/stepper/stepper.ts

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,57 @@
77
*/
88

99
import {
10-
Component, ContentChildren, EventEmitter, Input, Output, QueryList, OnInit,
11-
AfterViewChecked, AfterViewInit, Directive, ElementRef, ViewChild, ViewChildren
10+
ContentChildren,
11+
EventEmitter,
12+
Input,
13+
Output,
14+
QueryList,
15+
Directive,
16+
ViewChildren,
17+
// tslint doesn't recognize `ElementRef` is used since it's only used as a generic.
18+
// tslint:disable-next-line
19+
ElementRef
1220
} from '@angular/core';
1321
import {CdkStep} from './step';
14-
import {Observable} from 'rxjs/Observable';
15-
import {map} from 'rxjs/operator/map';
1622
import {LEFT_ARROW, RIGHT_ARROW, ENTER, TAB} from '../keyboard/keycodes';
23+
import {coerceNumberProperty} from '../coercion/number-property';
1724

1825
/** Used to generate unique ID for each stepper component. */
1926
let nextId = 0;
2027

21-
/** Change event emitted on focus or selection changes. */
22-
export class CdkStepEvent {
28+
/** Change event emitted on selection changes. */
29+
export class CdkStepperSelectionEvent {
2330
index: number;
2431
step: CdkStep;
2532
}
2633

2734
@Directive({
2835
selector: '[cdkStepper]',
2936
host: {
30-
'(keydown)': '_onKeydown($event)'
37+
'(focus)': '_setStepfocus()',
38+
'(keydown)': '_onKeydown($event)',
3139
},
3240
})
3341
export class CdkStepper {
42+
/** The list of step components that the stepper is holding. */
3443
@ContentChildren(CdkStep) _steps: QueryList<CdkStep>;
3544

45+
/** The list of step headers of the steps in the stepper. */
3646
@ViewChildren('stepHeader') _stepHeader: QueryList<ElementRef>;
3747

3848
/** The index of the currently selected step. */
3949
@Input()
40-
set selectedIndex(value: number) {
41-
this._selectedIndex = value;
50+
get selectedIndex() { return this._selectedIndex; }
51+
set selectedIndex(value: any) {
52+
this._selectedIndex = coerceNumberProperty(value);
4253
}
43-
get selectedIndex(): number { return this._selectedIndex; }
4454
private _selectedIndex: number;
4555

46-
/** Optional input to support both linear and non-linear stepper component. */
47-
@Input() linear: boolean = true;
48-
49-
/** Output to enable support for two-way binding on `[(selectedIndex)]` */
50-
@Output() get selectedIndexChange(): Observable<number> {
51-
return map.call(this.stepEvent, event => event.index);
52-
}
53-
54-
// @Output() get focusIndexChange(): Observable<number> {
55-
// return map.call(this.focusChange, event => event.index);
56-
// }
57-
5856
/** Event emitted when the selected step has changed. */
59-
@Output() stepEvent = new EventEmitter<CdkStepEvent>();
60-
61-
/** Event emitted when the focused step has changed. */
62-
@Output() focusChange = new EventEmitter<CdkStepEvent>();
63-
64-
/** The step that is currently selected. */
65-
get selectedStep(): CdkStep {
66-
return this._steps.toArray()[this._selectedIndex];
67-
}
68-
private _selectedStep: CdkStep;
57+
@Output() selectionChange = new EventEmitter<CdkStepperSelectionEvent>();
6958

7059
/** The index of the step that the focus is currently on. */
71-
get focusIndex(): number {return this._focusIndex; }
72-
private _focusIndex: number = 0;
60+
_focusIndex: number = 0;
7361

7462
private _groupId: number;
7563

@@ -78,28 +66,28 @@ export class CdkStepper {
7866
}
7967

8068
/** Selects and focuses the provided step. */
81-
selectStep(step: CdkStep): void {
69+
select(step: CdkStep): void {
8270
let stepsArray = this._steps.toArray();
8371
this._selectedIndex = stepsArray.indexOf(step);
84-
this.stepEvent.emit(this._emitStepEvent(this._selectedIndex));
72+
this.selectionChange.emit(this._createStepperSelectionEvent(this._selectedIndex));
8573
this._focusIndex = this._selectedIndex;
8674
this._setStepFocus();
8775
}
8876

8977
/** Selects and focuses the next step in list. */
90-
nextStep(): void {
78+
next(): void {
9179
if (this._selectedIndex == this._steps.length - 1) { return; }
9280
this._selectedIndex++;
93-
this.stepEvent.emit(this._emitStepEvent(this._selectedIndex));
81+
this.selectionChange.emit(this._createStepperSelectionEvent(this._selectedIndex));
9482
this._focusIndex = this._selectedIndex;
9583
this._setStepFocus();
9684
}
9785

9886
/** Selects and focuses the previous step in list. */
99-
previousStep(): void {
87+
previous(): void {
10088
if (this._selectedIndex == 0) { return; }
10189
this._selectedIndex--;
102-
this.stepEvent.emit(this._emitStepEvent(this._selectedIndex));
90+
this.selectionChange.emit(this._createStepperSelectionEvent(this._selectedIndex));
10391
this._focusIndex = this._selectedIndex;
10492
this._setStepFocus();
10593
}
@@ -114,11 +102,10 @@ export class CdkStepper {
114102
return `mat-step-content-${this._groupId}-${i}`;
115103
}
116104

117-
private _emitStepEvent(index: number): CdkStepEvent {
118-
const event = new CdkStepEvent();
105+
private _createStepperSelectionEvent(index: number): CdkStepperSelectionEvent {
106+
const event = new CdkStepperSelectionEvent();
119107
event.index = index;
120108
event.step = this._steps.toArray()[this._selectedIndex];
121-
this._selectedStep = event.step;
122109
return event;
123110
}
124111

@@ -138,16 +125,15 @@ export class CdkStepper {
138125
break;
139126
case ENTER:
140127
this._selectedIndex = this._focusIndex;
141-
this._emitStepEvent(this._selectedIndex);
128+
this._createStepperSelectionEvent(this._selectedIndex);
142129
break;
143130
}
144131
if (event.keyCode != TAB) {
145132
event.preventDefault();
146133
}
147134
}
148135

149-
_setStepFocus() {
136+
private _setStepFocus() {
150137
this._stepHeader.toArray()[this._focusIndex].nativeElement.focus();
151-
this.focusChange.emit(this._emitStepEvent(this._selectedIndex));
152138
}
153139
}

src/lib/stepper/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {MdStep} from './step';
1616
import {CdkStepperModule} from '@angular/cdk';
1717
import {MdCommonModule} from '../core';
1818
import {MdStepLabel} from './step-label';
19+
1920
@NgModule({
2021
imports: [MdCommonModule, CommonModule, PortalModule, MdButtonModule, CdkStepperModule],
2122
exports: [MdCommonModule, MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel],

src/lib/stepper/step-label.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import {Directive, TemplateRef, ViewContainerRef} from '@angular/core';
1010
import {CdkStepLabel} from '@angular/cdk';
11+
1112
@Directive({
1213
selector: '[md-step-label], [mat-step-label]',
1314
})

src/lib/stepper/step.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {Component, ContentChild, TemplateRef, ViewChild} from '@angular/core';
1010
import {CdkStep} from '@angular/cdk';
1111
import {MdStepLabel} from './step-label';
12+
1213
@Component({
1314
moduleId: module.id,
1415
selector: 'md-step, mat-step',

src/lib/stepper/stepper-horizontal.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
[id]="_getStepLabelId(i)"
55
[attr.aria-controls]="_getStepContentId(i)"
66
[attr.aria-selected]="selectedIndex == i"
7-
[tabIndex]="focusIndex == i ? 0 : -1"
8-
(click)="selectStep(step)"
7+
[tabIndex]="_focusIndex == i ? 0 : -1"
8+
(click)="select(step)"
99
(keydown)="_onKeydown($event)">
1010
<div *ngIf="step.active" class="active-step">{{i + 1}}</div>
1111
<div *ngIf="!step.active" class="inactive-step">{{i + 1}}</div>
@@ -22,7 +22,7 @@
2222
</div>
2323

2424
</div>
25-
<div *ngIf="!step.isLast" class="connector-line"></div>
25+
<div *ngIf="!step._isLast" class="connector-line"></div>
2626
</div>
2727
</div>
2828
<div *ngFor="let step of _steps; let i = index"
@@ -33,6 +33,6 @@
3333
<ng-container [ngTemplateOutlet]="step.content"></ng-container>
3434
</div>
3535
<div>
36-
<button md-button (click)="previousStep()">Back</button>
37-
<button md-button (click)="nextStep()">Next</button>
36+
<button md-button (click)="previous()">Back</button>
37+
<button md-button (click)="next()">Next</button>
3838
</div>

src/lib/stepper/stepper-horizontal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {Component, ContentChildren, QueryList} from '@angular/core';
1010
import {MdStep} from './step';
1111
import {CdkStepper} from '@angular/cdk';
12+
1213
@Component({
1314
moduleId: module.id,
1415
selector: 'md-horizontal-stepper, mat-horizontal-stepper',
@@ -18,4 +19,4 @@ import {CdkStepper} from '@angular/cdk';
1819
})
1920
export class MdHorizontalStepper extends CdkStepper {
2021
@ContentChildren(MdStep) _steps: QueryList<MdStep>;
21-
}
22+
}

src/lib/stepper/stepper-vertical.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
[id]="_getStepLabelId(i)"
55
[attr.aria-controls]="_getStepContentId(i)"
66
[attr.aria-selected]="selectedIndex == i"
7-
[tabIndex]="focusIndex == i ? 0 : -1"
8-
(click)="selectStep(step)"
7+
[tabIndex]="_focusIndex == i ? 0 : -1"
8+
(click)="select(step)"
99
(keydown)="_onKeydown($event)">
1010
<div *ngIf="step.active" class="activeStep">{{i + 1}}</div>
1111
<div *ngIf="!step.active" class="inactiveStep">{{i + 1}}</div>
@@ -22,17 +22,16 @@
2222
</div>
2323

2424
</div>
25-
<div *ngIf="!step.isLast" class="connector-line"></div>
25+
<div *ngIf="!step._isLast" class="connector-line"></div>
2626
<div *ngIf="i == selectedIndex" role="tabpanel"
2727
[id]="_getStepContentId(i)"
2828
[attr.aria-labelledby]="_getStepLabelId(i)"
2929
[attr.aria-expanded]="selectedIndex == i">
3030
<ng-container [ngTemplateOutlet]="step.content"></ng-container>
3131
</div>
32-
<div>
33-
<button md-button (click)="previousStep()">Back</button>
34-
<button md-button (click)="nextStep()">Next</button>
35-
<button md-button>Cancel</button>
32+
<div *ngIf="i == selectedIndex">
33+
<button md-button (click)="previous()">Back</button>
34+
<button md-button (click)="next()">Next</button>
3635
</div>
3736
</div>
3837
</div>

src/lib/stepper/stepper-vertical.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {Component, ContentChildren, QueryList} from '@angular/core';
1010
import {MdStep} from './step';
1111
import {CdkStepper} from '@angular/cdk';
12+
1213
@Component({
1314
moduleId: module.id,
1415
selector: 'md-vertical-stepper, mat-vertical-stepper',

0 commit comments

Comments
 (0)