Skip to content

Commit 5e2028b

Browse files
MelvinBotmkhutornyi
andcommitted
Disable scroll animation when typing in search
Search-triggered scrolls in useSearchFocusSync now pass animated: false so the list jumps instantly instead of smooth-scrolling when filtering. Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
1 parent 230c1c6 commit 5e2028b

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/components/SelectionList/BaseSelectionList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function BaseSelectionList<TItem extends ListItem>({
158158
}, []);
159159

160160
const scrollToIndex = useCallback(
161-
(index: number) => {
161+
(index: number, animated = true) => {
162162
// Bounds check: ensure index is valid for current data
163163
if (index < 0 || index >= data.length) {
164164
return;
@@ -168,7 +168,7 @@ function BaseSelectionList<TItem extends ListItem>({
168168
return;
169169
}
170170
try {
171-
listRef.current.scrollToIndex({index});
171+
listRef.current.scrollToIndex({index, animated});
172172
} catch (error) {
173173
// FlashList may throw if layout for this index doesn't exist yet
174174
// This can happen when data changes rapidly (e.g., during search filtering)

src/components/SelectionList/SelectionListWithSections/BaseSelectionListWithSections.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function BaseSelectionListWithSections<TItem extends ListItem>({
104104
hasKeyBeenPressed.current = true;
105105
};
106106

107-
const scrollToIndex = (index: number) => {
107+
const scrollToIndex = (index: number, animated = true) => {
108108
if (index < 0 || index >= flattenedData.length || !listRef.current) {
109109
return;
110110
}
@@ -113,7 +113,7 @@ function BaseSelectionListWithSections<TItem extends ListItem>({
113113
return;
114114
}
115115
try {
116-
listRef.current.scrollToIndex({index});
116+
listRef.current.scrollToIndex({index, animated});
117117
} catch (error) {
118118
// FlashList may throw if layout for this index doesn't exist yet
119119
// This can happen when data changes rapidly (e.g., during search filtering)

src/components/SelectionList/hooks/useSearchFocusSync.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type UseSearchFocusSyncParams<TItem extends ListItem, TData = TItem> = {
2222
shouldUpdateFocusedIndex: boolean;
2323

2424
/** Function to scroll to an index */
25-
scrollToIndex: (index: number) => void;
25+
scrollToIndex: (index: number, animated?: boolean) => void;
2626

2727
/** Function to set the focused index */
2828
setFocusedIndex: (index: number) => void;
@@ -71,7 +71,7 @@ function useSearchFocusSync<TItem extends ListItem, TData = TItem>({
7171
const foundSelectedItemIndex = data.findIndex(isItemSelected);
7272

7373
if (foundSelectedItemIndex !== -1 && !canSelectMultiple) {
74-
scrollToIndex(foundSelectedItemIndex);
74+
scrollToIndex(foundSelectedItemIndex, false);
7575
setFocusedIndex(foundSelectedItemIndex);
7676
return;
7777
}
@@ -90,7 +90,7 @@ function useSearchFocusSync<TItem extends ListItem, TData = TItem>({
9090
}
9191

9292
// Scroll to top of list and focus on first focusable item (not header)
93-
scrollToIndex(0);
93+
scrollToIndex(0, false);
9494
setFocusedIndex(firstFocusableIndex);
9595
}, [
9696
canSelectMultiple,

0 commit comments

Comments
 (0)