Skip to content

Commit

Permalink
Merge pull request #54994 from daledah/fix/54606
Browse files Browse the repository at this point in the history
fix: scroll list to the top when adding user
  • Loading branch information
robertjchen authored Jan 10, 2025
2 parents e3044c4 + c3866e6 commit 8d3f97b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -755,14 +755,11 @@ function BaseSelectionList<TItem extends ListItem>(
isTextInputFocusedRef.current = isTextInputFocused;
}, []);

useImperativeHandle(ref, () => ({scrollAndHighlightItem, clearInputAfterSelect, updateAndScrollToFocusedIndex, updateExternalTextInputFocus, scrollToIndex, getFocusedOption}), [
scrollAndHighlightItem,
clearInputAfterSelect,
updateAndScrollToFocusedIndex,
updateExternalTextInputFocus,
scrollToIndex,
getFocusedOption,
]);
useImperativeHandle(
ref,
() => ({scrollAndHighlightItem, clearInputAfterSelect, updateAndScrollToFocusedIndex, updateExternalTextInputFocus, scrollToIndex, getFocusedOption, focusTextInput}),
[scrollAndHighlightItem, clearInputAfterSelect, updateAndScrollToFocusedIndex, updateExternalTextInputFocus, scrollToIndex, getFocusedOption, focusTextInput],
);

/** Selects row when pressing Enter */
useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ENTER, selectFocusedOption, {
Expand Down
1 change: 1 addition & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ type SelectionListHandle = {
updateAndScrollToFocusedIndex: (newFocusedIndex: number) => void;
updateExternalTextInputFocus: (isTextInputFocused: boolean) => void;
getFocusedOption: () => ListItem | undefined;
focusTextInput: () => void;
};

type ItemLayout = {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ function NewChatPage() {

selectionListRef?.current?.clearInputAfterSelect?.();

selectionListRef.current?.focusTextInput();
selectionListRef?.current?.scrollToIndex(Math.max(newSelectedOptions.length - 1, 0), true);
setSelectedOptions(newSelectedOptions);
}

Expand Down

0 comments on commit 8d3f97b

Please sign in to comment.