Skip to content

Commit d16d8cf

Browse files
committed
fix(stepper): avoid breaking change in stepControl type
In #15134 we reworked the stepper not to depend on `@angular/forms` under the assumption that our limited `FormControl` interface would be enough to avoid a breaking change. Some people ended up being broken by the change so this PR reworks the `stepControl` type to avoid the breaking change. Fixes #15462.
1 parent f82259b commit d16d8cf

File tree

2 files changed

+56
-12
lines changed

2 files changed

+56
-12
lines changed

src/cdk/stepper/stepper.ts

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,7 @@ export class CdkStep implements OnChanges {
124124
@ViewChild(TemplateRef) content: TemplateRef<any>;
125125

126126
/** The top level abstract control of the step. */
127-
@Input() stepControl: {
128-
valid: boolean;
129-
invalid: boolean;
130-
pending: boolean;
131-
reset: () => void;
132-
};
127+
@Input() stepControl: FormControlLike;
133128

134129
/** Whether user has seen the expanded step content or not. */
135130
interacted = false;
@@ -516,3 +511,57 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
516511
return stepperElement === focusedElement || stepperElement.contains(focusedElement);
517512
}
518513
}
514+
515+
516+
/**
517+
* Simplified representation of a FormControl from @angular/forms.
518+
* Used to avoid having to bring in @angular/forms for a single optional interface.
519+
* @docs-private
520+
*/
521+
interface FormControlLike {
522+
asyncValidator: () => any | null;
523+
dirty: boolean;
524+
disabled: boolean;
525+
enabled: boolean;
526+
errors: {[key: string]: any} | null;
527+
invalid: boolean;
528+
parent: any;
529+
pending: boolean;
530+
pristine: boolean;
531+
root: FormControlLike;
532+
status: string;
533+
statusChanges: Observable<any>;
534+
touched: boolean;
535+
untouched: boolean;
536+
updateOn: any;
537+
valid: boolean;
538+
validator: () => any | null;
539+
value: any;
540+
valueChanges: Observable<any>;
541+
clearAsyncValidators(): void;
542+
clearValidators(): void;
543+
disable(opts?: any): void;
544+
enable(opts?: any): void;
545+
get(path: (string | number)[] | string): FormControlLike | null;
546+
getError(errorCode: string, path?: (string | number)[] | string): any;
547+
hasError(errorCode: string, path?: (string | number)[] | string): boolean;
548+
markAllAsTouched(): void;
549+
markAsDirty(opts?: any): void;
550+
markAsPending(opts?: any): void;
551+
markAsPristine(opts?: any): void;
552+
markAsTouched(opts?: any): void;
553+
markAsUntouched(opts?: any): void;
554+
patchValue(value: any, options?: Object): void;
555+
reset(value?: any, options?: Object): void;
556+
setAsyncValidators(newValidator: () => any | (() => any)[] | null): void;
557+
setErrors(errors: {[key: string]: any} | null, opts?: any): void;
558+
setParent(parent: any): void;
559+
setValidators(newValidator: () => any | (() => any)[] | null): void;
560+
setValue(value: any, options?: Object): void;
561+
updateValueAndValidity(opts?: any): void;
562+
patchValue(value: any, options?: any): void;
563+
registerOnChange(fn: Function): void;
564+
registerOnDisabledChange(fn: (isDisabled: boolean) => void): void;
565+
reset(formState?: any, options?: any): void;
566+
setValue(value: any, options?: any): void;
567+
}

tools/public_api_guard/cdk/stepper.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ export declare class CdkStep implements OnChanges {
1212
label: string;
1313
optional: boolean;
1414
state: StepState;
15-
stepControl: {
16-
valid: boolean;
17-
invalid: boolean;
18-
pending: boolean;
19-
reset: () => void;
20-
};
15+
stepControl: FormControlLike;
2116
stepLabel: CdkStepLabel;
2217
constructor(_stepper: CdkStepper, stepperOptions?: StepperOptions);
2318
ngOnChanges(): void;

0 commit comments

Comments
 (0)