Skip to content

Commit 23f54c1

Browse files
committed
fix(searchWhileComposing): control whether items should be filtered while composing
fixes ng-select#1296, default `true`
1 parent 048ef73 commit 23f54c1

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ map: {
152152
| [searchable] | `boolean` | `true` | no | Allow to search for value. Default `true`|
153153
| [readonly] | `boolean` | `false` | no | Set ng-select as readonly. Mostly used with reactive forms. |
154154
| [searchFn] | `(term: string, item: any) => boolean` | `null` | no | Allow to filter by custom search function |
155+
| [searchWhileComposing] | `boolean` | `true` | no | Whether items should be filtered while composition started |
155156
| [trackByFn] | `(item: any) => any` | `null` | no | Provide custom trackBy function |
156157
| [clearSearchOnAdd] | `boolean` | `true` | no | Clears search input when item is selected. Default `true`. Default `false` when **closeOnSelect** is `false` |
157158
| [selectOnTab] | `boolean` | `false` | no | Select marked dropdown item using tab. Default `false`|

src/ng-select/lib/ng-select.component.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3600,6 +3600,7 @@ describe('NgSelectComponent', () => {
36003600
`<ng-select [items]="citiesNames"
36013601
[addTag]="true"
36023602
placeholder="select value"
3603+
[searchWhileComposing]="false"
36033604
[(ngModel)]="selectedCity">
36043605
</ng-select>`);
36053606
select = fixture.componentInstance.select;

src/ng-select/lib/ng-select.component.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
107107
@Input() inputAttrs: { [key: string]: string } = {};
108108
@Input() tabIndex: number;
109109
@Input() readonly = false;
110+
@Input() searchWhileComposing = true;
110111
@Input() keyDownFn = (_: KeyboardEvent) => true;
111112

112113
@Input() @HostBinding('class.ng-select-typeahead') typeahead: Subject<string>;
@@ -192,14 +193,13 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
192193
private _pressedKeys: string[] = [];
193194
private _compareWith: CompareWithFn;
194195
private _clearSearchOnAdd: boolean;
196+
private _isComposing = false;
195197

196198
private readonly _destroy$ = new Subject<void>();
197199
private readonly _keyPress$ = new Subject<string>();
198200
private _onChange = (_: any) => { };
199201
private _onTouched = () => { };
200202

201-
private _isComposing = false;
202-
203203
clearItem = (item: any) => {
204204
const option = this.selectedItems.find(x => x.value === item);
205205
this.unselect(option);
@@ -535,12 +535,15 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
535535
}
536536

537537
onCompositionEnd(term: string) {
538+
if (this.searchWhileComposing) {
539+
return;
540+
}
538541
this._isComposing = false;
539542
this.filter(term);
540543
}
541544

542545
filter(term: string) {
543-
if (this._isComposing) {
546+
if (this._isComposing && !this.searchWhileComposing) {
544547
return;
545548
}
546549
this._changeSearch(term);

0 commit comments

Comments
 (0)