Skip to content

Commit

Permalink
fix(material/stepper): isErrorState accepts AbstractControl instead o…
Browse files Browse the repository at this point in the history
…f UntypedFormControl to avoid compiler errors when strict typing is enabled
  • Loading branch information
amysorto committed Jun 17, 2022
1 parent 3278214 commit c2c4356
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/material/core/common-behaviors/error-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

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

if (newState !== oldState) {
Expand Down
7 changes: 2 additions & 5 deletions src/material/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
ViewContainerRef,
ViewEncapsulation,
} from '@angular/core';
import {UntypedFormControl, FormGroupDirective, NgForm} from '@angular/forms';
import {AbstractControl, FormGroupDirective, NgForm} from '@angular/forms';
import {ErrorStateMatcher, ThemePalette} from '@angular/material/core';
import {TemplatePortal} from '@angular/cdk/portal';
import {Subject, Subscription} from 'rxjs';
Expand Down Expand Up @@ -110,10 +110,7 @@ export class MatStep extends CdkStep implements ErrorStateMatcher, AfterContentI
}

/** Custom error state matcher that additionally checks for validity of interacted form. */
isErrorState(
control: UntypedFormControl | null,
form: FormGroupDirective | NgForm | null,
): boolean {
isErrorState(control: AbstractControl | null, form: FormGroupDirective | NgForm | null): boolean {
const originalErrorState = this._errorStateMatcher.isErrorState(control, form);

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

0 comments on commit c2c4356

Please sign in to comment.