From d16d8cf5a0632640413b8fceba7070a64a4cd10e Mon Sep 17 00:00:00 2001 From: crisbeto Date: Wed, 13 Mar 2019 19:19:01 +0100 Subject: [PATCH] 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. --- src/cdk/stepper/stepper.ts | 61 ++++++++++++++++++++++--- tools/public_api_guard/cdk/stepper.d.ts | 7 +-- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/cdk/stepper/stepper.ts b/src/cdk/stepper/stepper.ts index 8261cd4fbeac..764d44a992b7 100644 --- a/src/cdk/stepper/stepper.ts +++ b/src/cdk/stepper/stepper.ts @@ -124,12 +124,7 @@ export class CdkStep implements OnChanges { @ViewChild(TemplateRef) content: TemplateRef; /** The top level abstract control of the step. */ - @Input() stepControl: { - valid: boolean; - invalid: boolean; - pending: boolean; - reset: () => void; - }; + @Input() stepControl: FormControlLike; /** Whether user has seen the expanded step content or not. */ interacted = false; @@ -516,3 +511,57 @@ export class CdkStepper implements AfterViewInit, OnDestroy { return stepperElement === focusedElement || stepperElement.contains(focusedElement); } } + + +/** + * Simplified representation of a FormControl from @angular/forms. + * Used to avoid having to bring in @angular/forms for a single optional interface. + * @docs-private + */ +interface FormControlLike { + asyncValidator: () => any | null; + dirty: boolean; + disabled: boolean; + enabled: boolean; + errors: {[key: string]: any} | null; + invalid: boolean; + parent: any; + pending: boolean; + pristine: boolean; + root: FormControlLike; + status: string; + statusChanges: Observable; + touched: boolean; + untouched: boolean; + updateOn: any; + valid: boolean; + validator: () => any | null; + value: any; + valueChanges: Observable; + clearAsyncValidators(): void; + clearValidators(): void; + disable(opts?: any): void; + enable(opts?: any): void; + get(path: (string | number)[] | string): FormControlLike | null; + getError(errorCode: string, path?: (string | number)[] | string): any; + hasError(errorCode: string, path?: (string | number)[] | string): boolean; + markAllAsTouched(): void; + markAsDirty(opts?: any): void; + markAsPending(opts?: any): void; + markAsPristine(opts?: any): void; + markAsTouched(opts?: any): void; + markAsUntouched(opts?: any): void; + patchValue(value: any, options?: Object): void; + reset(value?: any, options?: Object): void; + setAsyncValidators(newValidator: () => any | (() => any)[] | null): void; + setErrors(errors: {[key: string]: any} | null, opts?: any): void; + setParent(parent: any): void; + setValidators(newValidator: () => any | (() => any)[] | null): void; + setValue(value: any, options?: Object): void; + updateValueAndValidity(opts?: any): void; + patchValue(value: any, options?: any): void; + registerOnChange(fn: Function): void; + registerOnDisabledChange(fn: (isDisabled: boolean) => void): void; + reset(formState?: any, options?: any): void; + setValue(value: any, options?: any): void; +} diff --git a/tools/public_api_guard/cdk/stepper.d.ts b/tools/public_api_guard/cdk/stepper.d.ts index 710e2aec092a..34d58e5568cc 100644 --- a/tools/public_api_guard/cdk/stepper.d.ts +++ b/tools/public_api_guard/cdk/stepper.d.ts @@ -12,12 +12,7 @@ export declare class CdkStep implements OnChanges { label: string; optional: boolean; state: StepState; - stepControl: { - valid: boolean; - invalid: boolean; - pending: boolean; - reset: () => void; - }; + stepControl: FormControlLike; stepLabel: CdkStepLabel; constructor(_stepper: CdkStepper, stepperOptions?: StepperOptions); ngOnChanges(): void;