Skip to content

Commit 47b7f6b

Browse files
committed
fix(dropdown): track pressed item by id across updates
1 parent f8ece8b commit 47b7f6b

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

packages/core/src/app/widgetRenderer.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export class WidgetRenderer<S> {
258258
private baseEnabledById: ReadonlyMap<string, boolean> = new Map<string, boolean>();
259259
private pressableIds: ReadonlySet<string> = new Set<string>();
260260
private pressedId: string | null = null;
261-
private pressedDropdown: Readonly<{ id: string; index: number }> | null = null;
261+
private pressedDropdown: Readonly<{ id: string; itemId: string }> | null = null;
262262
private pressedVirtualList: Readonly<{ id: string; index: number }> | null = null;
263263
private pressedTable: Readonly<{ id: string; rowIndex: number }> | null = null;
264264
private pressedTableHeader: Readonly<{ id: string; columnIndex: number }> | null = null;
@@ -578,7 +578,7 @@ export class WidgetRenderer<S> {
578578
if (item && !item.divider && item.disabled !== true) {
579579
const prevSelected = this.dropdownSelectedIndexById.get(topDropdownId) ?? 0;
580580
this.dropdownSelectedIndexById.set(topDropdownId, itemIndex);
581-
this.pressedDropdown = Object.freeze({ id: topDropdownId, index: itemIndex });
581+
this.pressedDropdown = Object.freeze({ id: topDropdownId, itemId: item.id });
582582
return Object.freeze({ needsRender: itemIndex !== prevSelected });
583583
}
584584
}
@@ -591,14 +591,9 @@ export class WidgetRenderer<S> {
591591
const pressed = this.pressedDropdown;
592592
this.pressedDropdown = null;
593593

594-
if (
595-
pressed &&
596-
pressed.id === topDropdownId &&
597-
itemIndex !== null &&
598-
itemIndex === pressed.index
599-
) {
594+
if (pressed && pressed.id === topDropdownId && itemIndex !== null) {
600595
const item = dropdown.items[itemIndex];
601-
if (item && !item.divider && item.disabled !== true) {
596+
if (item && item.id === pressed.itemId && !item.divider && item.disabled !== true) {
602597
if (dropdown.onSelect) {
603598
try {
604599
dropdown.onSelect(item);

0 commit comments

Comments
 (0)