Skip to content

Commit

Permalink
fix(ngDoCheck): check error on markAllAsTouched()
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Balet committed Apr 15, 2024
1 parent a93a713 commit d9ea639
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mat-input-tel",
"version": "17.2.0",
"version": "17.3.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand All @@ -25,7 +25,7 @@
"@angular/platform-browser-dynamic": "^17.1.2",
"@angular/router": "^17.1.2",
"core-js": "^3.33.3",
"libphonenumber-js": "^1.10.55",
"libphonenumber-js": "^1.10.60",
"rxjs": "~7.8.1",
"tslib": "^2.6.2",
"zone.js": "~0.14.3"
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-mat-input-tel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mat-input-tel",
"version": "17.2.0",
"version": "17.3.0",
"author": {
"name": "Raphaël Balet",
"email": "[email protected]"
Expand All @@ -14,7 +14,7 @@
"@angular/forms": ">=15.x",
"@angular/platform-browser": ">=15.x",
"@angular/platform-browser-dynamic": ">=15.x",
"libphonenumber-js": "^1.10.55"
"libphonenumber-js": "^1.10.60"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,17 @@ export class NgxMatInputTelComponent

ngDoCheck(): void {
if (this.ngControl) {
const isInvalide = this.errorStateMatcher.isErrorState(
this.ngControl.control,
this._parentForm,
)
const oldState = this.errorState
const newState = this.errorStateMatcher.isErrorState(this.ngControl.control, this._parentForm)

this.errorState =
(isInvalide && !this.ngControl.control?.value) || (!this.focused ? isInvalide : false)
(newState && (!this.ngControl.control?.value || this.ngControl.control?.touched)) ||
(!this.focused ? newState : false)

if (oldState !== newState) {
this.errorState = newState
this.stateChanges.next()
}
}
}

Expand Down

0 comments on commit d9ea639

Please sign in to comment.