Skip to content

Commit eb9a47e

Browse files
committed
fix(stepper): unable to pass FormGroup as step control with strict type checking
Before angular#15134 landed, the stepper accepted an`AbstractControl` from `@angular/forms`. Unfortunately this PR accidentally changed the type for the `stepControl` input from `AbstractControl` to `FormControl`. This means that with strict template type checking, passing a `FormGroup` (like we do in our dev-app various times) causes type check failures. We need to adjust the `stepControl` type to accept an abstract control which is the base of a `FormControl` and `FormmGroup`.
1 parent 76f1444 commit eb9a47e

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/cdk/stepper/stepper.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import {FocusableOption, FocusKeyManager} from '@angular/cdk/a11y';
1010
import {Direction, Directionality} from '@angular/cdk/bidi';
1111
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';
12-
import {END, ENTER, HOME, SPACE, hasModifierKey} from '@angular/cdk/keycodes';
12+
import {END, ENTER, hasModifierKey, HOME, SPACE} from '@angular/cdk/keycodes';
13+
import {DOCUMENT} from '@angular/common';
1314
import {
1415
AfterViewInit,
1516
ChangeDetectionStrategy,
@@ -18,10 +19,11 @@ import {
1819
ContentChild,
1920
ContentChildren,
2021
Directive,
21-
EventEmitter,
2222
ElementRef,
23+
EventEmitter,
2324
forwardRef,
2425
Inject,
26+
InjectionToken,
2527
Input,
2628
OnChanges,
2729
OnDestroy,
@@ -31,13 +33,11 @@ import {
3133
TemplateRef,
3234
ViewChild,
3335
ViewEncapsulation,
34-
InjectionToken,
3536
} from '@angular/core';
36-
import {DOCUMENT} from '@angular/common';
37-
import {CdkStepLabel} from './step-label';
38-
import {Observable, Subject, of as obaservableOf} from 'rxjs';
37+
import {Observable, of as obaservableOf, Subject} from 'rxjs';
3938
import {startWith, takeUntil} from 'rxjs/operators';
4039
import {CdkStepHeader} from './step-header';
40+
import {CdkStepLabel} from './step-label';
4141

4242
/** Used to generate unique ID for each stepper component. */
4343
let nextId = 0;
@@ -124,7 +124,7 @@ export class CdkStep implements OnChanges {
124124
@ViewChild(TemplateRef, {static: true}) content: TemplateRef<any>;
125125

126126
/** The top level abstract control of the step. */
127-
@Input() stepControl: FormControlLike;
127+
@Input() stepControl: AbstractControlLike;
128128

129129
/** Whether user has seen the expanded step content or not. */
130130
interacted = false;
@@ -512,14 +512,13 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
512512
}
513513
}
514514

515-
516515
/**
517-
* Simplified representation of a FormControl from @angular/forms.
516+
* Simplified representation of an "AbstractControl" from @angular/forms.
518517
* Used to avoid having to bring in @angular/forms for a single optional interface.
519518
* @docs-private
520519
*/
521-
interface FormControlLike {
522-
asyncValidator: () => any | null;
520+
interface AbstractControlLike {
521+
asyncValidator: ((c: AbstractControlLike) => any) | null;
523522
dirty: boolean;
524523
disabled: boolean;
525524
enabled: boolean;
@@ -528,21 +527,21 @@ interface FormControlLike {
528527
parent: any;
529528
pending: boolean;
530529
pristine: boolean;
531-
root: FormControlLike;
530+
root: AbstractControlLike;
532531
status: string;
533532
statusChanges: Observable<any>;
534533
touched: boolean;
535534
untouched: boolean;
536535
updateOn: any;
537536
valid: boolean;
538-
validator: () => any | null;
537+
validator: ((c: AbstractControlLike) => any) | null;
539538
value: any;
540539
valueChanges: Observable<any>;
541540
clearAsyncValidators(): void;
542541
clearValidators(): void;
543542
disable(opts?: any): void;
544543
enable(opts?: any): void;
545-
get(path: (string | number)[] | string): FormControlLike | null;
544+
get(path: (string | number)[] | string): AbstractControlLike | null;
546545
getError(errorCode: string, path?: (string | number)[] | string): any;
547546
hasError(errorCode: string, path?: (string | number)[] | string): boolean;
548547
markAllAsTouched(): void;
@@ -553,15 +552,15 @@ interface FormControlLike {
553552
markAsUntouched(opts?: any): void;
554553
patchValue(value: any, options?: Object): void;
555554
reset(value?: any, options?: Object): void;
556-
setAsyncValidators(newValidator: () => any | (() => any)[] | null): void;
555+
setAsyncValidators(newValidator: (c: AbstractControlLike) => any |
556+
((c: AbstractControlLike) => any)[] | null): void;
557557
setErrors(errors: {[key: string]: any} | null, opts?: any): void;
558558
setParent(parent: any): void;
559-
setValidators(newValidator: () => any | (() => any)[] | null): void;
559+
setValidators(newValidator: (c: AbstractControlLike) => any |
560+
((c: AbstractControlLike) => any)[] | null): void;
560561
setValue(value: any, options?: Object): void;
561562
updateValueAndValidity(opts?: any): void;
562563
patchValue(value: any, options?: any): void;
563-
registerOnChange(fn: Function): void;
564-
registerOnDisabledChange(fn: (isDisabled: boolean) => void): void;
565564
reset(formState?: any, options?: any): void;
566565
setValue(value: any, options?: any): void;
567566
}

0 commit comments

Comments
 (0)