Skip to content

Commit

Permalink
fix: remove input if searchable is false (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao committed Apr 12, 2018
1 parent 68b9a7e commit 2149517
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/ng-select/ng-select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@
[ngTemplateOutletContext]="{ items: selectedValues, clear: clearItem }">
</ng-template>

<div *ngIf="showFilter()" class="ng-input">
<div *ngIf="!isDisabled" class="ng-input">
<div *ngIf="!searchable"
tabindex="0"
(focus)="onInputFocus()"
(blur)="onInputBlur()"
role="combobox"
[attr.aria-expanded]="isOpen"
[attr.aria-owns]="isOpen ? dropdownId : null"
[attr.aria-activedescendant]="isOpen ? itemsList?.markedItem?.htmlId : null">
</div>
<input #filterInput
*ngIf="searchable"
type="text"
autocomplete="off"
[readOnly]="!searchable"
[value]="filterValue"
(input)="filter(filterInput.value)"
(focus)="onInputFocus()"
Expand Down
7 changes: 5 additions & 2 deletions src/ng-select/ng-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1772,9 +1772,12 @@ describe('NgSelectComponent', function () {
[(ngModel)]="selectedCity">
</ng-select>`);

fixture.componentInstance.select.filter('vilnius');
const select = fixture.componentInstance.select;
select.filter('vilnius');
tickAndDetectChanges(fixture);
expect(fixture.componentInstance.select.filterValue).toBe(null);
const filterInput = select.elementRef.nativeElement.querySelector('input');
expect(select.filterValue).toBeNull();
expect(filterInput).toBeNull();
}));

it('should mark first item on filter', fakeAsync(() => {
Expand Down
7 changes: 3 additions & 4 deletions src/ng-select/ng-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,6 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
!this.isLoading;
}

showFilter() {
return !this.isDisabled;
}

showNoItemsFound() {
const empty = this.itemsList.filteredItems.length === 0;
return ((empty && !this._isTypeahead && !this.loading) ||
Expand Down Expand Up @@ -436,6 +432,9 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
}

focusSearchInput() {
if (!this.filterInput) {
return;
}
this.filterInput.nativeElement.focus();
this.filterInput.nativeElement.select();
}
Expand Down

0 comments on commit 2149517

Please sign in to comment.