Skip to content

Commit f04d4d7

Browse files
authored
Merge pull request #2427 from SMassola/issue-2426
fix(ibm-combo-box): show list of new items that match current search
2 parents 262c8d6 + 9451fdd commit f04d4d7

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

src/combobox/combobox.component.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,28 @@ describe("Combo box", () => {
160160
element = fixture.debugElement.query(By.css("input"));
161161
expect(element.nativeElement.getAttribute("placeholder")).toBe("placeholder");
162162
});
163+
164+
it("should display dropdown list when new items are passed that match the current search string", () => {
165+
fixture = TestBed.createComponent(ComboboxTest);
166+
wrapper = fixture.componentInstance;
167+
fixture.detectChanges();
168+
169+
element = fixture.debugElement.query(By.css("ibm-combo-box"));
170+
171+
const textInput = element.nativeElement.querySelector(".bx--text-input");
172+
textInput.value = "f";
173+
textInput.dispatchEvent(new Event("input"));
174+
175+
wrapper.items = [
176+
{content: "four", selected: false},
177+
{content: "five", selected: false},
178+
{content: "six", selected: false}
179+
];
180+
181+
fixture.detectChanges();
182+
183+
const itemEls = fixture.debugElement.queryAll(By.css(".bx--list-box__menu-item"));
184+
185+
expect(itemEls.length).toEqual(2);
186+
});
163187
});

src/combobox/combobox.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
747747
if (!matches) {
748748
const selected = this.view.getSelected();
749749
if (!selected || !selected[0]) {
750-
this.view.filterBy("");
750+
this.view.filterBy(searchString);
751751
}
752752
}
753753
}

src/dropdown/dropdown.component.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
OnDestroy,
1313
HostBinding,
1414
TemplateRef,
15-
ApplicationRef,
1615
AfterViewInit
1716
} from "@angular/core";
1817
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from "@angular/forms";
@@ -357,7 +356,6 @@ export class Dropdown implements OnInit, AfterContentInit, AfterViewInit, OnDest
357356
protected elementRef: ElementRef,
358357
protected i18n: I18n,
359358
protected dropdownService: DropdownService,
360-
protected appRef: ApplicationRef,
361359
protected elementService: ElementService) {}
362360

363361
/**
@@ -415,8 +413,6 @@ export class Dropdown implements OnInit, AfterContentInit, AfterViewInit, OnDest
415413
this.checkForReorder();
416414
this.selected.emit(event);
417415
}
418-
// manually tick the app so the view picks up any changes
419-
this.appRef.tick();
420416
});
421417
}
422418

src/dropdown/list/dropdown-list.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
ViewChild,
1010
ElementRef,
1111
ViewChildren,
12-
QueryList
12+
QueryList,
13+
ApplicationRef
1314
} from "@angular/core";
1415
import { Observable, isObservable, Subscription, of } from "rxjs";
1516
import { first } from "rxjs/operators";
@@ -226,7 +227,7 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnDest
226227
/**
227228
* Creates an instance of `DropdownList`.
228229
*/
229-
constructor(public elementRef: ElementRef, protected i18n: I18n) {}
230+
constructor(public elementRef: ElementRef, protected i18n: I18n, protected appRef: ApplicationRef) {}
230231

231232
/**
232233
* Retrieves array of list items and index of the selected item after view has rendered.
@@ -276,9 +277,7 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnDest
276277
this.displayItems = this._items;
277278
this.updateIndex();
278279
this.setupFocusObservable();
279-
setTimeout(() => {
280-
this.doEmitSelect();
281-
});
280+
this.doEmitSelect();
282281
}
283282

284283
/**
@@ -576,6 +575,7 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnDest
576575
this.index = this.displayItems.indexOf(item);
577576
this.highlightedItem = this.getItemId(this.index);
578577
this.doEmitSelect(false);
578+
this.appRef.tick();
579579
}
580580
}
581581

0 commit comments

Comments
 (0)