Skip to content

Commit

Permalink
add comment and refector separate variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed Nov 21, 2023
1 parent 714440f commit faa9cd5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/components/CategoryPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function CategoryPicker({selectedCategory, policyCategories, policyRecentlyUsedC

const headerMessage = OptionsListUtils.getHeaderMessageForNonUserList(lodashGet(sections, '[0].data.length', 0) > 0, searchValue);
const shouldShowTextInput = !isCategoriesCountBelowThreshold;
const selectedOptionKey = lodashGet(_.filter(lodashGet(sections, '[0].data', []), (category) => category.searchText === selectedCategory)[0], 'keyForList');

return (
<OptionsSelector
Expand All @@ -62,8 +63,10 @@ function CategoryPicker({selectedCategory, policyCategories, policyRecentlyUsedC
sections={sections}
selectedOptions={selectedOptions}
value={searchValue}
// Focus the first option when searching
focusedIndex={0}
initiallyFocusedOptionKey={lodashGet(_.filter(lodashGet(sections, '[0].data', []), (category) => category.searchText === selectedCategory)[0], 'keyForList')}
// Focus the selected option on first load
initiallyFocusedOptionKey={selectedOptionKey}
headerMessage={headerMessage}
shouldShowTextInput={shouldShowTextInput}
textInputLabel={translate('common.search')}
Expand Down
6 changes: 5 additions & 1 deletion src/components/TagPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm

const headerMessage = OptionsListUtils.getHeaderMessageForNonUserList(lodashGet(sections, '[0].data.length', 0) > 0, searchValue);

const selectedOptionKey = lodashGet(_.filter(lodashGet(sections, '[0].data', []), (policyTag) => policyTag.searchText === selectedTag)[0], 'keyForList');

return (
<OptionsSelector
optionHoveredStyle={styles.hoveredComponentBG}
Expand All @@ -66,8 +68,10 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm
isRowMultilineSupported
shouldShowTextInput={shouldShowTextInput}
value={searchValue}
// Focus the first option when searching
focusedIndex={0}
initiallyFocusedOptionKey={lodashGet(_.filter(lodashGet(sections, '[0].data', []), (policyTag) => policyTag.searchText === selectedTag)[0], 'keyForList')}
// Focus the selected option on first load
initiallyFocusedOptionKey={selectedOptionKey}
onChangeText={setSearchValue}
onSelectRow={onSubmit}
/>
Expand Down

0 comments on commit faa9cd5

Please sign in to comment.