Skip to content

Commit 9200c6f

Browse files
committed
refactor: rename match to isErrorState
1 parent 55fb514 commit 9200c6f

File tree

6 files changed

+27
-24
lines changed

6 files changed

+27
-24
lines changed

src/lib/core/error/error-options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import {FormGroupDirective, NgForm, NgControl} from '@angular/forms';
1212
/** Error state matcher that matches when a control is invalid and dirty. */
1313
@Injectable()
1414
export class ShowOnDirtyErrorStateMatcher implements ErrorStateMatcher {
15-
match(control: NgControl | null, form: FormGroupDirective | NgForm | null): boolean {
15+
isErrorSate(control: NgControl | null, form: FormGroupDirective | NgForm | null): boolean {
1616
return control ? !!(control.invalid && (control.dirty || (form && form.submitted))) : false;
1717
}
1818
}
1919

2020
/** Provider that defines how form controls behave with regards to displaying error messages. */
2121
@Injectable()
2222
export class ErrorStateMatcher {
23-
match(control: NgControl | null, form: FormGroupDirective | NgForm | null): boolean {
23+
isErrorSate(control: NgControl | null, form: FormGroupDirective | NgForm | null): boolean {
2424
return control ? !!(control.invalid && (control.touched || (form && form.submitted))) : false;
2525
}
2626
}

src/lib/input/input-container.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,9 @@ describe('MdInputContainer with forms', () => {
895895
declarations: [
896896
MdInputContainerWithFormErrorMessages
897897
],
898-
providers: [{ provide: ErrorStateMatcher, useValue: { match: globalErrorStateMatcher } }]
898+
providers: [
899+
{ provide: ErrorStateMatcher, useValue: { isErrorSate: globalErrorStateMatcher } }
900+
]
899901
});
900902

901903
let fixture = TestBed.createComponent(MdInputContainerWithFormErrorMessages);
@@ -1252,7 +1254,7 @@ class MdInputContainerWithCustomErrorStateMatcher {
12521254

12531255
errorState = false;
12541256
customErrorStateMatcher: ErrorStateMatcher = {
1255-
match: () => this.errorState
1257+
isErrorSate: () => this.errorState
12561258
};
12571259
}
12581260

src/lib/input/input-container.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ export class MdInputDirective implements OnChanges, OnDestroy, DoCheck {
299299

300300
/** Re-evaluates the error state. This is only relevant with @angular/forms. */
301301
private _updateErrorState() {
302-
const oldState = this._isErrorState;
303-
const matcher = this.errorStateMatcher || this._globalErrorStateMatcher;
304-
const newState = matcher.match(this._ngControl, this._parentFormGroup || this._parentForm);
302+
let oldState = this._isErrorState;
303+
let matcher = this.errorStateMatcher || this._globalErrorStateMatcher;
304+
let newState = matcher.isErrorSate(this._ngControl, this._parentFormGroup || this._parentForm);
305305

306306
if (newState !== oldState) {
307307
this._isErrorState = newState;

src/lib/input/input.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ A placeholder for the input can be specified in one of two ways: either using th
6262
attribute on the `input` or `textarea`, or using an `md-placeholder` element in the
6363
`md-input-container`. Using both will raise an error.
6464

65-
Global default placeholder options can be specified by setting the `MD_PLACEHOLDER_GLOBAL_OPTIONS` provider. This setting will apply to all components that support the floating placeholder.
65+
Global default placeholder options can be specified by setting the `MD_PLACEHOLDER_GLOBAL_OPTIONS`
66+
provider. This setting will apply to all components that support the floating placeholder.
6667

6768
```ts
6869
@NgModule({
@@ -110,12 +111,12 @@ warn color.
110111

111112
### Custom Error Matcher
112113

113-
By default, error messages are shown when the control is invalid and either the user has interacted with
114-
(touched) the element or the parent form has been submitted. If you wish to override this
114+
By default, error messages are shown when the control is invalid and either the user has interacted
115+
with (touched) the element or the parent form has been submitted. If you wish to override this
115116
behavior (e.g. to show the error as soon as the invalid control is dirty or when a parent form group
116117
is invalid), you can use the `errorStateMatcher` property of the `mdInput`. To use this property,
117-
create a function in your component class that returns a boolean. A result of `true` will display
118-
the error messages.
118+
create an `ErrorStateMatcher` object in your component class that has a `isErrorSate` function which
119+
returns a boolean. A result of `true` will display the error messages.
119120

120121
```html
121122
<md-input-container>
@@ -126,22 +127,22 @@ the error messages.
126127

127128
```ts
128129
class MyErrorStateMatcher implements ErrorStateMatcher {
129-
match(control: NgControl | null, form: FormGroupDirective | NgForm | null): boolean {
130+
isErrorSate(control: NgControl | null, form: FormGroupDirective | NgForm | null): boolean {
130131
// Error when invalid control is dirty, touched, or submitted
131132
const isSubmitted = form && form.submitted;
132-
return !!(control.invalid && (control.dirty || control.touched || isSubmitted)));
133+
return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted)));
133134
}
134135
}
135136
```
136137

137-
A global error state matcher can be specified by setting the `ErrorOptions` provider. This applies
138-
to all inputs. For convenience, `ShowOnDirtyErrorStateMatcher` is available in order to globally
139-
cause input errors to show when the input is dirty and invalid.
138+
A global error state matcher can be specified by setting the `ErrorStateMatcher` provider. This
139+
applies to all inputs. For convenience, `ShowOnDirtyErrorStateMatcher` is available in order to
140+
globally cause input errors to show when the input is dirty and invalid.
140141

141142
```ts
142143
@NgModule({
143144
providers: [
144-
{provide: ErrorOptions, useClass: ShowOnDirtyErrorStateMatcher}
145+
{provide: ErrorStateMatcher, useClass: ShowOnDirtyErrorStateMatcher}
145146
]
146147
})
147148
```

src/lib/select/select.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,24 +2689,24 @@ describe('MdSelect', () => {
26892689
expect(component.control.invalid).toBe(false);
26902690
expect(component.select._isErrorState()).toBe(false);
26912691

2692-
customErrorFixture.componentInstance.errorStateMatcher = { match: matcher };
2692+
customErrorFixture.componentInstance.errorStateMatcher = { isErrorSate: matcher };
26932693
customErrorFixture.detectChanges();
26942694

26952695
expect(component.select._isErrorState()).toBe(true);
26962696
expect(matcher).toHaveBeenCalled();
26972697
});
26982698

26992699
it('should be able to override the error matching behavior via the injection token', () => {
2700-
const errorOptions: ErrorStateMatcher = {
2701-
match: jasmine.createSpy('error state matcher').and.returnValue(true)
2700+
const errorStateMatcher: ErrorStateMatcher = {
2701+
isErrorSate: jasmine.createSpy('error state matcher').and.returnValue(true)
27022702
};
27032703

27042704
fixture.destroy();
27052705

27062706
TestBed.resetTestingModule().configureTestingModule({
27072707
imports: [MdSelectModule, ReactiveFormsModule, FormsModule, NoopAnimationsModule],
27082708
declarations: [SelectInsideFormGroup],
2709-
providers: [{ provide: ErrorStateMatcher, useValue: errorOptions }],
2709+
providers: [{ provide: ErrorStateMatcher, useValue: errorStateMatcher }],
27102710
});
27112711

27122712
const errorFixture = TestBed.createComponent(SelectInsideFormGroup);
@@ -2715,7 +2715,7 @@ describe('MdSelect', () => {
27152715
errorFixture.detectChanges();
27162716

27172717
expect(component.select._isErrorState()).toBe(true);
2718-
expect(errorOptions.match).toHaveBeenCalled();
2718+
expect(errorStateMatcher.isErrorSate).toHaveBeenCalled();
27192719
});
27202720
});
27212721

src/lib/select/select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
639639
/** Whether the select is in an error state. */
640640
_isErrorState(): boolean {
641641
const matcher = this.errorStateMatcher || this._globalErrorStateMatcher;
642-
return matcher.match(this._control, this._parentFormGroup || this._parentForm);
642+
return matcher.isErrorSate(this._control, this._parentFormGroup || this._parentForm);
643643
}
644644

645645
/**

0 commit comments

Comments
 (0)