@@ -5,8 +5,10 @@ import ScreenWrapper from '@components/ScreenWrapper';
55import SelectionList from '@components/SelectionList' ;
66import SingleSelectListItem from '@components/SelectionList/ListItem/SingleSelectListItem' ;
77import useDebouncedState from '@hooks/useDebouncedState' ;
8+ import useInitialSelection from '@hooks/useInitialSelection' ;
89import useLocalize from '@hooks/useLocalize' ;
910import searchOptions from '@libs/searchOptions' ;
11+ import moveInitialSelectionToTop from '@libs/SelectionListOrderUtils' ;
1012import StringUtils from '@libs/StringUtils' ;
1113import CONST from '@src/CONST' ;
1214
@@ -44,6 +46,8 @@ function PushRowModal({isVisible, selectedOption, onOptionChange, onClose, optio
4446 const { translate} = useLocalize ( ) ;
4547
4648 const [ searchValue , debouncedSearchValue , setSearchValue ] = useDebouncedState ( '' ) ;
49+ const initialSelectedValue = useInitialSelection ( selectedOption || undefined , { isVisible} ) ;
50+ const initialSelectedValues = initialSelectedValue ? [ initialSelectedValue ] : [ ] ;
4751
4852 const options = useMemo (
4953 ( ) =>
@@ -57,6 +61,8 @@ function PushRowModal({isVisible, selectedOption, onOptionChange, onClose, optio
5761 [ optionsList , selectedOption ] ,
5862 ) ;
5963
64+ const orderedOptions = moveInitialSelectionToTop ( options , initialSelectedValues ) ;
65+
6066 const handleSelectRow = ( option : ListItemType ) => {
6167 onOptionChange ( option . value ) ;
6268 onClose ( ) ;
@@ -67,7 +73,7 @@ function PushRowModal({isVisible, selectedOption, onOptionChange, onClose, optio
6773 setSearchValue ( '' ) ;
6874 } ;
6975
70- const searchResults = searchOptions ( debouncedSearchValue , options ) ;
76+ const searchResults = searchOptions ( debouncedSearchValue , debouncedSearchValue ? options : orderedOptions ) ;
7177
7278 const textInputOptions = useMemo (
7379 ( ) => ( {
@@ -102,7 +108,8 @@ function PushRowModal({isVisible, selectedOption, onOptionChange, onClose, optio
102108 ListItem = { SingleSelectListItem }
103109 onSelectRow = { handleSelectRow }
104110 textInputOptions = { textInputOptions }
105- initiallyFocusedItemKey = { selectedOption }
111+ searchValueForFocusSync = { debouncedSearchValue }
112+ initiallyFocusedItemKey = { initialSelectedValue }
106113 disableMaintainingScrollPosition
107114 shouldShowTooltips = { false }
108115 showScrollIndicator
0 commit comments