Skip to content

Commit

Permalink
fix(typeahead): properly support disabled inputs
Browse files Browse the repository at this point in the history
Closes #703
  • Loading branch information
pkozlowski-opensource committed Sep 8, 2016
1 parent 237b4d5 commit bf61640
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/typeahead/typeahead.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@ describe('ngb-typeahead', () => {
expect(getNativeInput(compiled)).toHaveCssClass('ng-valid');
expect(getNativeInput(compiled)).not.toHaveCssClass('ng-invalid');
});

it('should support disabled state', async(() => {
const html = `
<form>
<input type="text" [(ngModel)]="model" name="control" [disabled]="true" [ngbTypeahead]="findObjects" />
</form>`;
const fixture = createTestComponent(html);
fixture.whenStable().then(() => {
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(getNativeInput(compiled).disabled).toBeTruthy();
});
}));
});

describe('select event', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/typeahead/typeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export class NgbTypeahead implements OnInit,

writeValue(value) { this._writeInputValue(this._formatItemForInput(value)); }

setDisabledState(isDisabled: boolean): void {
this._renderer.setElementProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
}

/**
* @internal
*/
Expand Down

0 comments on commit bf61640

Please sign in to comment.