Skip to content

Commit d7936b0

Browse files
feat(simple-combo): update scroll position based on selection
1 parent 8039216 commit d7936b0

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

projects/igniteui-angular/src/lib/simple-combo/simple-combo.component.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,20 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
149149
if (this.composing) {
150150
this.comboInput.focus();
151151
}
152+
if (this.comboInput.value.length === 0) {
153+
this.dropdown.focusedItem = this.dropdown.items[0];
154+
this.dropdownContainer.nativeElement.focus();
155+
}
152156
});
153157
this.dropdown.closed.pipe(takeUntil(this.destroy$)).subscribe(() => {
154158
this.composing = false;
155159
});
156160
this.dropdown.closing.pipe(takeUntil(this.destroy$)).subscribe(() => {
157161
const selection = this.selectionService.first_item(this.id);
158162
this.comboInput.value = selection !== undefined && selection !== null ? selection : '';
163+
this._onChangeCallback(selection);
159164
});
160-
this.dropdown.opening.pipe(takeUntil(this.destroy$)).subscribe(() => {
161-
if (!this.comboInput.value.length) {
162-
this.clearSelection();
163-
}
164-
});
165+
165166
super.ngAfterViewInit();
166167
}
167168

@@ -171,6 +172,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
171172
this._onChangeCallback(this.searchValue);
172173
if (this.collapsed) {
173174
this.open();
175+
this.virtDir.scrollTo(0);
174176
}
175177
super.handleInputChange(event);
176178
}
@@ -251,6 +253,14 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
251253
}
252254
}
253255

256+
/** @hidden @internal */
257+
public onClick(event: Event) {
258+
super.onClick(event);
259+
if (this.comboInput.value.length === 0) {
260+
this.virtDir.scrollTo(0);
261+
}
262+
}
263+
254264
protected findMatch = (element: any): boolean => {
255265
const value = this.displayKey ? element[this.displayKey] : element;
256266
return value.toString().toLowerCase().includes(this.searchValue.trim().toLowerCase());

0 commit comments

Comments
 (0)