Skip to content

Commit 1632f76

Browse files
MelvinBotmkhutornyi
andcommitted
Restore initiallyFocusedItemKey for auto-scroll on mount
Re-adds initiallyFocusedItemKey so the list scrolls to the first preselected item when opening the page. This does not cause scroll jumps on item selection because FlashList's initialScrollIndex only applies on mount and useArrowKeyFocusManager ignores prop changes after its initial useState call. Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
1 parent edc56c3 commit 1632f76

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

src/components/Search/SearchMultipleSelectionPicker.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function SearchMultipleSelectionPicker<T extends string | string[]>({
4747

4848
sectionData.sort((a, b) => sortOptionsWithEmptyValue(a.value.toString(), b.value.toString(), localeCompare));
4949

50+
const firstSelectedKey = sectionData.find((item) => item.isSelected)?.keyForList;
5051
const noResultsFound = !sectionData.length;
5152
const sections = noResultsFound
5253
? []
@@ -93,6 +94,7 @@ function SearchMultipleSelectionPicker<T extends string | string[]>({
9394
<SelectionListWithSections
9495
sections={sections}
9596
ListItem={MultiSelectListItem}
97+
initiallyFocusedItemKey={firstSelectedKey}
9698
shouldClearInputOnSelect={false}
9799
shouldShowTextInput={shouldShowTextInput}
98100
textInputOptions={textInputOptions}

0 commit comments

Comments
 (0)