Skip to content

Commit

Permalink
fix(typeahead): don't close dropdown on typeahead input click
Browse files Browse the repository at this point in the history
Closes #1853
Closes #1989
  • Loading branch information
ymeine authored and pkozlowski-opensource committed Nov 24, 2017
1 parent 9ad8f43 commit fa9c080
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/typeahead/typeahead.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ describe('ngb-typeahead', () => {
expect(getWindow(compiled)).toBeNull();
});

it('should not be closed on input click', () => {
const fixture = createTestComponent(`<input type="text" [ngbTypeahead]="find"/>`);
const compiled = fixture.nativeElement;

changeInput(compiled, 'one');
fixture.detectChanges();
expect(getWindow(compiled)).not.toBeNull();

getNativeInput(compiled).click();
expect(getWindow(compiled)).not.toBeNull();
});

it('should be closed when ESC is pressed', () => {
const fixture = createTestComponent(`<input type="text" [ngbTypeahead]="find"/>`);
const compiled = fixture.nativeElement;
Expand Down
8 changes: 7 additions & 1 deletion src/typeahead/typeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let nextWindowId = 0;
host: {
'(blur)': 'handleBlur()',
'[class.open]': 'isPopupOpen()',
'(document:click)': 'dismissPopup()',
'(document:click)': 'onDocumentClick($event)',
'(keydown)': 'handleKeyDown($event)',
'autocomplete': 'off',
'autocapitalize': 'off',
Expand Down Expand Up @@ -214,6 +214,12 @@ export class NgbTypeahead implements ControlValueAccessor,
this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
}

onDocumentClick(event) {
if (event.target !== this._elementRef.nativeElement) {
this.dismissPopup();
}
}

/**
* Dismisses typeahead popup window
*/
Expand Down

0 comments on commit fa9c080

Please sign in to comment.