Skip to content

Commit 6570a08

Browse files
wnvkojackofdiamond5
authored andcommitted
feat(simple-combo): scroll to correct item when open dropdown, #9832
WIP: scrolling to selected item introduce a lot of flickering
1 parent c0f016f commit 6570a08

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { IgxButtonModule } from '../directives/button/button.directive';
1818
import { IgxForOfModule } from '../directives/for-of/for_of.directive';
1919
import { IgxRippleModule } from '../directives/ripple/ripple.directive';
2020
import { IgxTextSelectionModule } from '../directives/text-selection/text-selection.directive';
21-
import { IgxToggleModule } from '../directives/toggle/toggle.directive';
21+
import { IgxToggleDirective, IgxToggleModule } from '../directives/toggle/toggle.directive';
2222
import { IgxDropDownModule } from '../drop-down/public_api';
2323
import { IgxIconModule, IgxIconService } from '../icon/public_api';
2424
import { IgxInputGroupModule, IgxInputGroupType, IGX_INPUT_GROUP_TYPE } from '../input-group/public_api';
@@ -147,9 +147,19 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
147147
this.comboInput.focus();
148148
}
149149
if (this.comboInput.value.length === 0) {
150-
this.dropdown.focusedItem = this.dropdown.items[0];
150+
this.dropdown.navigateFirst();
151151
this.dropdownContainer.nativeElement.focus();
152152
}
153+
if (this.selection.length > 0) {
154+
const index = this.virtDir.igxForOf.findIndex(e => {
155+
let current = e[this.valueKey];
156+
if (this.valueKey === null || this.valueKey === undefined) {
157+
current = e;
158+
}
159+
return current === this.selection[0];
160+
});
161+
this.dropdown.navigateItem(index);
162+
}
153163
});
154164
this.dropdown.closed.pipe(takeUntil(this.destroy$)).subscribe(() => {
155165
this.composing = false;
@@ -169,7 +179,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
169179
this._onChangeCallback(this.searchValue);
170180
if (this.collapsed) {
171181
this.open();
172-
this.virtDir.scrollTo(0);
182+
this.dropdown.navigateFirst();
173183
}
174184
super.handleInputChange(event);
175185
}
@@ -223,6 +233,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
223233
this.clearSelection(true);
224234
if (this.collapsed) {
225235
this.open();
236+
this.dropdown.navigateFirst();
226237
} else {
227238
this.focusSearchInput(true);
228239
}

0 commit comments

Comments
 (0)