Skip to content

Commit fc2d768

Browse files
authored
Merge pull request #4012 from IgniteUI/vslavov/select-nav-closed
fix(select): always focus the selected item in igx-select
2 parents 119cdae + 9b0a44b commit fc2d768

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

projects/igniteui-angular/src/lib/select/select.component.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,22 @@ describe('igxSelect', () => {
16181618
tick(500);
16191619
fixture.detectChanges();
16201620
}));
1621+
1622+
it('Should navigate through items when dropdown is closed and initial value is passed', fakeAsync(() => {
1623+
select.close();
1624+
tick();
1625+
fixture.detectChanges();
1626+
spyOn(select, 'navigateNext').and.callThrough();
1627+
const choices = select.children.toArray();
1628+
select.value = choices[5].value;
1629+
tick();
1630+
fixture.detectChanges();
1631+
select.input.nativeElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }));
1632+
tick();
1633+
fixture.detectChanges();
1634+
expect(select.navigateNext).toHaveBeenCalled();
1635+
expect(select.value).toEqual(choices[6].value);
1636+
}));
16211637
});
16221638
describe('Positioning tests: ', () => {
16231639
const defaultWindowToListOffset = 5;

projects/igniteui-angular/src/lib/select/select.component.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { IgxSelectItemComponent } from './select-item.component';
1818
import { SelectPositioningStrategy } from './select-positioning-strategy';
1919

2020
import { OverlaySettings, AbsoluteScrollStrategy } from '../services/index';
21-
import { IGX_DROPDOWN_BASE, ISelectionEventArgs } from '../drop-down/drop-down.common';
21+
import { IGX_DROPDOWN_BASE, ISelectionEventArgs, Navigate } from '../drop-down/drop-down.common';
2222
import { IgxSelectItemNavigationDirective } from './select-navigation.directive';
2323
import { CancelableEventArgs } from '../core/utils';
2424
import { IgxLabelDirective } from '../directives/label/label.directive';
@@ -272,7 +272,13 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
272272
this.scrollToItem(this.selectedItem);
273273
}
274274

275-
/** @hidden @internal */
275+
protected navigate(direction: Navigate, currentIndex?: number) {
276+
if (this.collapsed && this.selectedItem) {
277+
this.navigateItem(this.selectedItem.itemIndex);
278+
}
279+
super.navigate(direction, currentIndex);
280+
}
281+
276282
private setSelection(item: IgxDropDownItemBase) {
277283
if (item && item.value !== undefined && item.value !== null) {
278284
this.selection.set(this.id, new Set([item]));

0 commit comments

Comments
 (0)