-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(select): add support for custom error state matcher #7443
feat(select): add support for custom error state matcher #7443
Conversation
dfeaa7f
to
ee63ccd
Compare
src/lib/input/input.ts
Outdated
@@ -232,7 +223,8 @@ export class MatInput implements MatFormFieldControl<any>, OnChanges, OnDestroy, | |||
const oldState = this.errorState; | |||
const ngControl = this.ngControl; | |||
const parent = this._parentFormGroup || this._parentForm; | |||
const newState = ngControl && this.errorStateMatcher(ngControl.control as FormControl, parent); | |||
const matcher = this.errorStateMatcher || this._defaultErrorStateMatcher; | |||
const newState = ngControl && matcher.isErrorState(ngControl, parent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isErrorState
accepts null ngControl
, so no need to check here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/lib/select/select.ts
Outdated
|
||
return !!(isInvalid && (isTouched || isSubmitted)); | ||
return ngControl && matcher.isErrorState(ngControl, parent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, no need to check that ngControl
is non-null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ee63ccd
to
21ec8ee
Compare
src/lib/core/error/error-options.ts
Outdated
@Injectable() | ||
export class ShowOnDirtyErrorStateMatcher implements ErrorStateMatcher { | ||
isErrorState(control: NgControl | null, form: FormGroupDirective | NgForm | null): boolean { | ||
return control ? !!(control.invalid && (control.dirty || (form && form.submitted))) : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this work? return !!(control && control.invalid && (control.dirty || form && form.submitted))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should, I don't remember why we went with the ternary initially.
src/lib/core/error/error-options.ts
Outdated
@Injectable() | ||
export class ErrorStateMatcher { | ||
isErrorState(control: NgControl | null, form: FormGroupDirective | NgForm | null): boolean { | ||
return control ? !!(control.invalid && (control.touched || (form && form.submitted))) : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return !!(control && control.invalid && (control.touched || form && form.submitted))
fixes #7419 |
21ec8ee
to
de279dc
Compare
Addressed the feedback @mmalerba. |
Breaking changes comment for switching from function to ErrorStateMatcher class? |
@crisbeto Rebase? |
de279dc
to
ad38bb9
Compare
Rebased. |
* Allows for the select's error state matcher to be overwritten through an `@Input`. * Switches `MatSelect` over to use the same global provider for its error state as `MatInput`. **Note:** This is a resubmit of angular#6147 that works with our latest setup and excludes a few changes. Fixes angular#7419.
ad38bb9
to
a3c364c
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
@Input
.MatSelect
over to use the same global provider for its error state asMatInput
.Note: This is a resubmit of #6147 that works with our latest setup and excludes a few changes.
Fixes #7419