Skip to content

Commit 4378b1e

Browse files
authored
Merge pull request Expensify#89984 from software-mansion-labs/fix/custom-single-select-popup-item-height
Fix SingleSelectPopup height with non-default item heights
2 parents f5fac30 + 5fe87b3 commit 4378b1e

4 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/components/Search/FilterComponents/SingleSelect.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,25 @@ type SingleSelectProps<T> = {
3535
/** Whether SelectionList of popup should stay mounted when popup is not visible. */
3636
shouldShowList?: boolean;
3737

38+
/** Custom height for each item in the list */
39+
itemHeight?: number;
40+
3841
hasTitle?: boolean;
3942
hasHeader?: boolean;
4043
};
4144

42-
function SingleSelect<T extends string>({value, items, isSearchable, searchPlaceholder, selectionListStyle, shouldShowList = true, hasTitle, hasHeader, onChange}: SingleSelectProps<T>) {
45+
function SingleSelect<T extends string>({
46+
value,
47+
items,
48+
isSearchable,
49+
searchPlaceholder,
50+
selectionListStyle,
51+
shouldShowList = true,
52+
hasTitle,
53+
hasHeader,
54+
onChange,
55+
itemHeight,
56+
}: SingleSelectProps<T>) {
4357
const {translate} = useLocalize();
4458
const styles = useThemeStyles();
4559
const [selectedItem, setSelectedItem] = useState(value);
@@ -99,7 +113,7 @@ function SingleSelect<T extends string>({value, items, isSearchable, searchPlace
99113
hasHeader={hasHeader}
100114
hasTitle={hasTitle}
101115
isSearchable={isSearchable}
102-
itemHeight={variables.optionRowHeight}
116+
itemHeight={itemHeight ?? variables.optionRowHeight}
103117
>
104118
<Activity mode={shouldShowList ? 'visible' : 'hidden'}>
105119
<SelectionList
@@ -108,7 +122,11 @@ function SingleSelect<T extends string>({value, items, isSearchable, searchPlace
108122
ListItem={SingleSelectListItem}
109123
onSelectRow={updateSelectedItem}
110124
textInputOptions={textInputOptions}
111-
style={{contentContainerStyle: [styles.pb0], ...selectionListStyle}}
125+
style={{
126+
contentContainerStyle: [styles.pb0],
127+
...selectionListStyle,
128+
listItemWrapperStyle: [itemHeight !== undefined && {minHeight: itemHeight}, selectionListStyle?.listItemWrapperStyle],
129+
}}
112130
shouldUpdateFocusedIndex={isSearchable}
113131
initiallyFocusedItemKey={isSearchable ? value?.value : undefined}
114132
shouldShowLoadingPlaceholder={!noResultsFound}

src/components/Search/FilterDropdowns/SingleSelectPopup.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type SingleSelectPopupProps<T> = {
3939
/** Custom styles for the SelectionList */
4040
selectionListStyle?: SelectionListStyle;
4141

42+
/** Custom height for each item in the list. Overrides the default row height and adjusts the popover size accordingly. */
43+
itemHeight?: number;
44+
4245
/** Whether SelectionList of popup should stay mounted when popup is not visible. */
4346
shouldShowList?: boolean;
4447
};
@@ -55,6 +58,7 @@ function SingleSelectPopup<T extends string>({
5558
defaultValue,
5659
style,
5760
selectionListStyle,
61+
itemHeight,
5862
shouldShowList = true,
5963
}: SingleSelectPopupProps<T>) {
6064
const [selectedItem, setSelectedItem] = useState(value);
@@ -90,6 +94,7 @@ function SingleSelectPopup<T extends string>({
9094
searchPlaceholder={searchPlaceholder}
9195
selectionListStyle={selectionListStyle}
9296
shouldShowList={shouldShowList}
97+
itemHeight={itemHeight}
9398
/>
9499
</ListFilterHeightContextProvider>
95100
</BasePopup>

src/pages/domain/Members/DomainMembersPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Navigation from '@navigation/Navigation';
3131
import type {PlatformStackScreenProps} from '@navigation/PlatformStackNavigation/types';
3232
import type {DomainSplitNavigatorParamList} from '@navigation/types';
3333
import BaseDomainMembersPage from '@pages/domain/BaseDomainMembersPage';
34+
import variables from '@styles/variables';
3435
import CONST from '@src/CONST';
3536
import ONYXKEYS from '@src/ONYXKEYS';
3637
import ROUTES from '@src/ROUTES';
@@ -82,7 +83,7 @@ function DomainMembersPage({route}: DomainMembersPageProps) {
8283
closeOverlay={closeOverlay}
8384
onChange={handleGroupChange}
8485
defaultValue={groupOptions.at(0)?.value}
85-
selectionListStyle={{listItemWrapperStyle: {minHeight: 40}}}
86+
itemHeight={variables.optionRowHeightCompact}
8687
shouldShowList={isExpanded}
8788
/>
8889
);

src/pages/workspace/WorkspaceMembersPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ function WorkspaceMembersPage({personalDetails, route, policy}: WorkspaceMembers
657657
closeOverlay={closeOverlay}
658658
onChange={handleRoleFilterChange}
659659
defaultValue={roleFilterOptions.at(0)?.value}
660-
selectionListStyle={{listItemWrapperStyle: styles.mnh40}}
660+
itemHeight={variables.optionRowHeightCompact}
661661
/>
662662
);
663663

0 commit comments

Comments
 (0)