Skip to content

Commit c970ff9

Browse files
committed
fix(material/stepper): isErrorState accepts AbstractControl instead of UntypedFormControl to avoid compiler errors when strict typing is enabled (#25105)
(cherry picked from commit 79fc046)
1 parent 301f6b0 commit c970ff9

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/material/core/common-behaviors/error-state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {UntypedFormControl, FormGroupDirective, NgControl, NgForm} from '@angular/forms';
9+
import {AbstractControl, FormGroupDirective, NgControl, NgForm} from '@angular/forms';
1010
import {Subject} from 'rxjs';
1111
import {ErrorStateMatcher} from '../error/error-options';
1212
import {AbstractConstructor, Constructor} from './constructor';
@@ -59,7 +59,7 @@ export function mixinErrorState<T extends Constructor<HasErrorState>>(
5959
const oldState = this.errorState;
6060
const parent = this._parentFormGroup || this._parentForm;
6161
const matcher = this.errorStateMatcher || this._defaultErrorStateMatcher;
62-
const control = this.ngControl ? (this.ngControl.control as UntypedFormControl) : null;
62+
const control = this.ngControl ? (this.ngControl.control as AbstractControl) : null;
6363
const newState = matcher.isErrorState(control, parent);
6464

6565
if (newState !== oldState) {

src/material/stepper/stepper.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
ViewContainerRef,
3838
ViewEncapsulation,
3939
} from '@angular/core';
40-
import {UntypedFormControl, FormGroupDirective, NgForm} from '@angular/forms';
40+
import {AbstractControl, FormGroupDirective, NgForm} from '@angular/forms';
4141
import {ErrorStateMatcher, ThemePalette} from '@angular/material/core';
4242
import {TemplatePortal} from '@angular/cdk/portal';
4343
import {Subject, Subscription} from 'rxjs';
@@ -110,10 +110,7 @@ export class MatStep extends CdkStep implements ErrorStateMatcher, AfterContentI
110110
}
111111

112112
/** Custom error state matcher that additionally checks for validity of interacted form. */
113-
isErrorState(
114-
control: UntypedFormControl | null,
115-
form: FormGroupDirective | NgForm | null,
116-
): boolean {
113+
isErrorState(control: AbstractControl | null, form: FormGroupDirective | NgForm | null): boolean {
117114
const originalErrorState = this._errorStateMatcher.isErrorState(control, form);
118115

119116
// Custom error state checks for the validity of form that is not submitted or touched

tools/public_api_guard/material/stepper.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
```ts
66

77
import { _AbstractConstructor } from '@angular/material/core';
8+
import { AbstractControl } from '@angular/forms';
89
import { AfterContentInit } from '@angular/core';
910
import { AfterViewInit } from '@angular/core';
1011
import { AnimationEvent as AnimationEvent_2 } from '@angular/animations';
@@ -42,7 +43,6 @@ import { Subject } from 'rxjs';
4243
import { TemplatePortal } from '@angular/cdk/portal';
4344
import { TemplateRef } from '@angular/core';
4445
import { ThemePalette } from '@angular/material/core';
45-
import { UntypedFormControl } from '@angular/forms';
4646
import { ViewContainerRef } from '@angular/core';
4747

4848
// @public
@@ -59,7 +59,7 @@ export function MAT_STEPPER_INTL_PROVIDER_FACTORY(parentIntl: MatStepperIntl): M
5959
export class MatStep extends CdkStep implements ErrorStateMatcher, AfterContentInit, OnDestroy {
6060
constructor(stepper: MatStepper, _errorStateMatcher: ErrorStateMatcher, _viewContainerRef: ViewContainerRef, stepperOptions?: StepperOptions);
6161
color: ThemePalette;
62-
isErrorState(control: UntypedFormControl | null, form: FormGroupDirective | NgForm | null): boolean;
62+
isErrorState(control: AbstractControl | null, form: FormGroupDirective | NgForm | null): boolean;
6363
_lazyContent: MatStepContent;
6464
// (undocumented)
6565
ngAfterContentInit(): void;

0 commit comments

Comments
 (0)