Skip to content

Commit a7ecf25

Browse files
committed
fix(combo-dropdown): keep activeDescendant in a field
1 parent cfde1fa commit a7ecf25

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

projects/igniteui-angular/combo/src/combo/combo-dropdown.component.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I
1717
public combo = inject<IgxComboBase>(IGX_COMBO_COMPONENT);
1818
protected comboAPI = inject(IgxComboAPIService);
1919

20+
private _activeDescendantId: string | null = null;
21+
2022
/** @hidden @internal */
2123
@Input({ transform: booleanAttribute })
2224
public singleMode = false;
@@ -54,6 +56,40 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I
5456
return null;
5557
}
5658

59+
/**
60+
* @hidden @internal
61+
*/
62+
public override get focusedItem(): IgxDropDownItemBaseDirective {
63+
return super.focusedItem;
64+
}
65+
66+
/**
67+
* @hidden @internal
68+
* Returns a stable aria-activedescendant id, unaffected by virtual scroll position.
69+
* The base class computes this from the live focusedItem getter, which reads from the
70+
* children QueryList. During virtual scroll the QueryList is recycled, so the getter
71+
* can return null mid-CD-cycle causing NG0100 in zoneless apps. The id is cached instead.
72+
*/
73+
public override get activeDescendant(): string | null {
74+
return this._activeDescendantId;
75+
}
76+
77+
/** @hidden @internal */
78+
public override set focusedItem(item: IgxDropDownItemBaseDirective) {
79+
if (!item) {
80+
this._activeDescendantId = null;
81+
} else if (item.id !== undefined) {
82+
this._activeDescendantId = item.id;
83+
} else {
84+
// Virtual { value, index } object passed by navigateItem() under virtual scrolling.
85+
const resolved = this.children?.find(e => e.index === item.index);
86+
if (resolved) {
87+
this._activeDescendantId = resolved.id;
88+
}
89+
}
90+
super.focusedItem = item;
91+
}
92+
5793
/**
5894
* Get all non-header items
5995
*
@@ -141,6 +177,7 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I
141177
return;
142178
}
143179
this.comboAPI.set_selected_item(item.itemID);
180+
this._activeDescendantId = item.id;
144181
this._focusedItem = item;
145182
this.combo.setActiveDescendant();
146183
}

projects/igniteui-angular/drop-down/src/drop-down/drop-down.base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export abstract class IgxDropDownBaseDirective implements IDropDownList, OnInit
172172
* This is used to update the `aria-activedescendant` attribute of
173173
* the IgxDropDownNavigationDirective host element.
174174
*/
175-
public get activeDescendant (): string {
175+
public get activeDescendant (): string | null {
176176
return this.focusedItem ? this.focusedItem.id : null;
177177
}
178178

0 commit comments

Comments
 (0)