Skip to content

Commit aa22517

Browse files
committed
fix(DropdownInput): return the index of entry instead of object reference
1 parent 19d7d7d commit aa22517

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

frontend/src/components/widgets/inputs/DropdownInput.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,23 @@
5555
activeEntry = makeActiveEntry();
5656
}
5757
58+
function getEntryIndex(entry: MenuListEntry): number {
59+
return entries.flat().findIndex(item => item.value === entry.value)
60+
}
61+
5862
// Called when the `activeEntry` two-way binding on this component's MenuList component is changed, or by the `selectedIndex()` watcher above (but we want to skip that case)
5963
function watchActiveEntry(activeEntry: MenuListEntry) {
6064
if (activeEntrySkipWatcher) {
6165
activeEntrySkipWatcher = false;
6266
} else if (activeEntry !== DASH_ENTRY) {
6367
// We need to set to the initial value first to track a right history step, as if we hover in initial selection.
6468
if (initialSelectedIndex !== undefined) onhoverInEntry?.(initialSelectedIndex);
65-
onselectedIndex?.(entries.flat().indexOf(activeEntry));
69+
onselectedIndex?.(getEntryIndex(activeEntry));
6670
}
6771
}
6872
6973
function dispatchHoverInEntry(hoveredEntry: MenuListEntry) {
70-
onhoverInEntry?.(entries.flat().indexOf(hoveredEntry));
74+
onhoverInEntry?.(getEntryIndex(hoveredEntry));
7175
}
7276
7377
function dispatchHoverOutEntry() {

0 commit comments

Comments
 (0)