diff --git a/ng-select/ng-select.component.html b/ng-select/ng-select.component.html index 4dc0cd20f..9293a7229 100644 --- a/ng-select/ng-select.component.html +++ b/ng-select/ng-select.component.html @@ -1,4 +1,4 @@ -
+
{{placeholder}}
@@ -40,7 +40,7 @@
-
{ + fixture = createTestingModule( + NgSelectFilterTestCmp, + ` + `); + + const selectInput = fixture.debugElement.query(By.css('.ng-control')); + // open + selectInput.triggerEventHandler('click', { stopPropagation: () => { } }); + tickAndDetectChanges(fixture); + expect(fixture.componentInstance.select.isOpen).toBe(true); + + // close + selectInput.triggerEventHandler('click', { stopPropagation: () => { } }); + tickAndDetectChanges(fixture); + expect(fixture.componentInstance.select.isOpen).toBe(false); + })); + it('should not filter when searchable false', fakeAsync(() => { fixture = createTestingModule( NgSelectFilterTestCmp, diff --git a/ng-select/ng-select.component.ts b/ng-select/ng-select.component.ts index 421872ccb..17bc1b6b8 100644 --- a/ng-select/ng-select.component.ts +++ b/ng-select/ng-select.component.ts @@ -231,6 +231,14 @@ export class NgSelectComponent implements OnInit, OnDestroy, OnChanges, AfterVie this.isDisabled = isDisabled; } + toggle() { + if (!this.isOpen) { + this.open(); + } else { + this.close(); + } + } + open() { if (this.isDisabled || this.isOpen) { return; @@ -251,7 +259,7 @@ export class NgSelectComponent implements OnInit, OnDestroy, OnChanges, AfterVie this.closeEvent.emit(); } - toggle(item: NgOption) { + toggleItem(item: NgOption) { if (!item || item.disabled || this.isDisabled) { return; } @@ -494,7 +502,7 @@ export class NgSelectComponent implements OnInit, OnDestroy, OnChanges, AfterVie private handleEnter($event: KeyboardEvent) { if (this.isOpen) { if (this.itemsList.markedItem) { - this.toggle(this.itemsList.markedItem); + this.toggleItem(this.itemsList.markedItem); } else if (this.addTag) { this.selectTag(); }