Skip to content

Commit 1d80047

Browse files
authored
fix(web): scroll project picker to top on first result (#34113)
1 parent 79bca43 commit 1d80047

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,7 @@ function OpenCommandPaletteDialog(props: {
26502650
scrollCommandPaletteRowIntoView(
26512651
resultListRef.current,
26522652
resultRows.rowIndexByItemIndex[0] ?? 0,
2653+
true,
26532654
);
26542655
return;
26552656
}
@@ -2921,7 +2922,11 @@ function OpenCommandPaletteDialog(props: {
29212922
setHighlightedItemValue(typeof value === "string" ? value : null);
29222923
const rowIndex = resultRows.rowIndexByItemIndex[eventDetails.index];
29232924
if (eventDetails.reason === "keyboard" && rowIndex !== undefined) {
2924-
scrollCommandPaletteRowIntoView(resultListRef.current, rowIndex);
2925+
scrollCommandPaletteRowIntoView(
2926+
resultListRef.current,
2927+
rowIndex,
2928+
eventDetails.index === 0,
2929+
);
29252930
}
29262931
}}
29272932
onValueChange={(nextQuery, { event }) => handleQueryChange(nextQuery, event.target)}

‎apps/web/src/components/CommandPaletteResults.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ export function CommandPaletteResults(props: CommandPaletteResultsProps) {
7878
);
7979
}
8080

81-
export function scrollCommandPaletteRowIntoView(list: LegendListRef | null, rowIndex: number) {
81+
export function scrollCommandPaletteRowIntoView(
82+
list: LegendListRef | null,
83+
rowIndex: number,
84+
isFirstItem: boolean,
85+
) {
86+
if (isFirstItem) {
87+
void list?.scrollToOffset({ offset: 0, animated: false });
88+
return;
89+
}
8290
void list?.scrollIndexIntoView({
8391
index: rowIndex,
8492
animated: false,

0 commit comments

Comments
 (0)