Skip to content

Commit bf61640

Browse files
fix(typeahead): properly support disabled inputs
Closes #703
1 parent 237b4d5 commit bf61640

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/typeahead/typeahead.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,19 @@ describe('ngb-typeahead', () => {
366366
expect(getNativeInput(compiled)).toHaveCssClass('ng-valid');
367367
expect(getNativeInput(compiled)).not.toHaveCssClass('ng-invalid');
368368
});
369+
370+
it('should support disabled state', async(() => {
371+
const html = `
372+
<form>
373+
<input type="text" [(ngModel)]="model" name="control" [disabled]="true" [ngbTypeahead]="findObjects" />
374+
</form>`;
375+
const fixture = createTestComponent(html);
376+
fixture.whenStable().then(() => {
377+
fixture.detectChanges();
378+
const compiled = fixture.nativeElement;
379+
expect(getNativeInput(compiled).disabled).toBeTruthy();
380+
});
381+
}));
369382
});
370383

371384
describe('select event', () => {

src/typeahead/typeahead.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ export class NgbTypeahead implements OnInit,
152152

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

155+
setDisabledState(isDisabled: boolean): void {
156+
this._renderer.setElementProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
157+
}
158+
155159
/**
156160
* @internal
157161
*/

0 commit comments

Comments
 (0)