Skip to content

Commit

Permalink
fix(ValidationMessage): Disable change detection OnPush to get called…
Browse files Browse the repository at this point in the history
… on first change cycle
  • Loading branch information
atlwendy authored and benjamincharity committed Feb 12, 2020
1 parent f420172 commit 7181dce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions terminus-ui/input/src/input.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ describe(`TsInputComponent`, function() {
expect(el.getAttribute('required')).toEqual('');
});

test(`should display validation message if the form control is required and validation fails`, () => {
const fixture = createComponent(TestComponents.FormControlAttrRequired);
fixture.detectChanges();
const component = getInputInstance(fixture);
const el = component.inputElement.nativeElement;
el.focus();

component.onBlur();
fixture.detectChanges();

const validation = fixture.debugElement.query(By.css('.c-validation-message'));
expect(validation.nativeElement.textContent.trim()).toEqual('Required');
});

test(`should set required if the required flag is set`, () => {
const fixture = createComponent(TestComponents.AttrInputRequired);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let nextUniqueId = 0;

/**
* A presentational component to render validation messages
* NOTE: ChangeDetectionStrategy.OnPush is disabled here because it affects control getting to this service on the first change cycle.
*
* @example
* <ts-validation-messages
Expand All @@ -29,13 +30,13 @@ let nextUniqueId = 0;
*
* <example-url>https://getterminus.github.io/ui-demos-release/components/validation</example-url>
*/
// tslint:disable: prefer-on-push-component-change-detection
@Component({
selector: 'ts-validation-messages',
templateUrl: './validation-messages.component.html',
styleUrls: ['./validation-messages.component.scss'],
host: { class: 'ts-validation-messages' },
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
exportAs: 'tsValidationMessages',
})
export class TsValidationMessagesComponent implements OnDestroy {
Expand Down

0 comments on commit 7181dce

Please sign in to comment.