@@ -5,7 +5,6 @@ import { IgxStepComponent } from './step/step.component';
5
5
/** @hidden @internal */
6
6
@Injectable ( )
7
7
export class IgxStepperService {
8
-
9
8
public activeStep : IgxStepComponent ;
10
9
public previousActiveStep : IgxStepComponent ;
11
10
public focusedStep : IgxStepComponent ;
@@ -20,46 +19,45 @@ export class IgxStepperService {
20
19
}
21
20
22
21
/**
23
- * Adds the step to the `expandedSteps` set and fires the steps change event
24
- *
25
- * @param step target step
26
- * @param uiTrigger is the event triggered by a ui interraction (so we know if we should animate)
27
- * @returns void
22
+ * Activates the step, fires the steps change event and plays animations.
28
23
*/
29
24
public expand ( step : IgxStepComponent ) : void {
30
25
if ( this . activeStep === step ) {
31
26
return ;
32
27
}
33
28
34
- const argsCanceled = this . emitActivatingEvent ( step ) ;
35
-
36
- if ( ! argsCanceled ) {
37
- this . collapsingSteps . delete ( step ) ;
29
+ const cancel = this . emitActivatingEvent ( step ) ;
30
+ if ( cancel ) {
31
+ return ;
32
+ }
38
33
39
- this . previousActiveStep = this . activeStep ;
40
- this . activeStep = step ;
41
- this . activeStep . activeChange . emit ( true ) ;
34
+ this . collapsingSteps . delete ( step ) ;
42
35
43
- this . collapsingSteps . add ( this . previousActiveStep ) ;
44
- this . visitedSteps . add ( this . activeStep ) ;
36
+ this . previousActiveStep = this . activeStep ;
37
+ this . activeStep = step ;
38
+ this . activeStep . activeChange . emit ( true ) ;
45
39
46
- if ( this . stepper . orientation === IgxStepperOrienatation . Vertical ) {
47
- this . previousActiveStep . playCloseAnimation (
48
- this . previousActiveStep . contentContainer
49
- ) ;
50
- this . activeStep . cdr . detectChanges ( ) ;
40
+ this . collapsingSteps . add ( this . previousActiveStep ) ;
41
+ this . visitedSteps . add ( this . activeStep ) ;
51
42
52
- this . activeStep . playOpenAnimation (
53
- this . activeStep . contentContainer
54
- ) ;
55
- } else {
56
- this . activeStep . cdr . detectChanges ( ) ;
57
- this . stepper . playHorizontalAnimations ( ) ;
58
- }
43
+ if ( this . stepper . orientation === IgxStepperOrienatation . Vertical ) {
44
+ this . previousActiveStep . playCloseAnimation (
45
+ this . previousActiveStep . contentContainer
46
+ ) ;
47
+ this . activeStep . cdr . detectChanges ( ) ;
59
48
49
+ this . activeStep . playOpenAnimation (
50
+ this . activeStep . contentContainer
51
+ ) ;
52
+ } else {
53
+ this . activeStep . cdr . detectChanges ( ) ;
54
+ this . stepper . playHorizontalAnimations ( ) ;
60
55
}
61
56
}
62
57
58
+ /**
59
+ * Activates the step and fires the steps change event without playing animations.
60
+ */
63
61
public expandThroughApi ( step : IgxStepComponent ) : void {
64
62
if ( this . activeStep === step ) {
65
63
return ;
@@ -83,6 +81,9 @@ export class IgxStepperService {
83
81
this . previousActiveStep ?. activeChange . emit ( false ) ;
84
82
}
85
83
84
+ /**
85
+ * Collapses the currently active step and fires the change event.
86
+ */
86
87
public collapse ( step : IgxStepComponent ) : void {
87
88
if ( this . activeStep === step ) {
88
89
return ;
@@ -91,19 +92,27 @@ export class IgxStepperService {
91
92
this . collapsingSteps . delete ( step ) ;
92
93
}
93
94
95
+ /**
96
+ * Determines the steps that should be marked as visited based on the active step.
97
+ */
98
+ public calculateVisitedSteps ( ) : void {
99
+ this . stepper . steps . forEach ( step => {
100
+ if ( step . index <= this . activeStep . index ) {
101
+ this . visitedSteps . add ( step ) ;
102
+ } else {
103
+ this . visitedSteps . delete ( step ) ;
104
+ }
105
+ } ) ;
106
+ }
107
+
108
+ /**
109
+ * Determines the steps that should be disabled in linear mode based on the validity of the active step.
110
+ */
94
111
public calculateLinearDisabledSteps ( ) : void {
95
112
if ( this . activeStep . isValid ) {
96
113
const firstRequiredIndex = this . getNextRequiredStep ( ) ;
97
114
if ( firstRequiredIndex !== - 1 ) {
98
- this . stepper . steps . forEach ( s => {
99
- if ( s . index > this . activeStep . index ) {
100
- if ( s . index <= firstRequiredIndex ) {
101
- this . linearDisabledSteps . delete ( s ) ;
102
- } else {
103
- this . linearDisabledSteps . add ( s ) ;
104
- }
105
- }
106
- } ) ;
115
+ this . updateLinearDisabledSteps ( firstRequiredIndex ) ;
107
116
} else {
108
117
this . linearDisabledSteps . clear ( ) ;
109
118
}
@@ -128,6 +137,23 @@ export class IgxStepperService {
128
137
return args . cancel ;
129
138
}
130
139
140
+ /**
141
+ * Updates the linearDisabled steps from the current active step to the next required invalid step.
142
+ *
143
+ * @param toIndex the index of the last step that should be enabled.
144
+ */
145
+ private updateLinearDisabledSteps ( toIndex : number ) : void {
146
+ this . stepper . steps . forEach ( s => {
147
+ if ( s . index > this . activeStep . index ) {
148
+ if ( s . index <= toIndex ) {
149
+ this . linearDisabledSteps . delete ( s ) ;
150
+ } else {
151
+ this . linearDisabledSteps . add ( s ) ;
152
+ }
153
+ }
154
+ } ) ;
155
+ }
156
+
131
157
private getNextRequiredStep ( ) : number {
132
158
return this . stepper . steps . findIndex ( s => s . index > this . activeStep . index && ! s . optional && ! s . disabled && ! s . isValid ) ;
133
159
}
0 commit comments