Skip to content

Commit 64ae99e

Browse files
puneetlathOSBotify
authored andcommitted
Merge pull request #37389 from neonbhai/selection-list-multiline-fix
[Categories] Add support for long category names (cherry picked from commit b384904)
1 parent 31907e0 commit 64ae99e

File tree

7 files changed

+27
-5
lines changed

7 files changed

+27
-5
lines changed

src/components/CategoryPicker/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function CategoryPicker({selectedCategory, policyCategories, policyRecentlyUsedC
7070
onSelectRow={onSubmit}
7171
ListItem={RadioListItem}
7272
initiallyFocusedOptionKey={selectedOptionKey}
73+
isRowMultilineSupported
7374
/>
7475
);
7576
}

src/components/SelectionList/BaseSelectionList.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function BaseSelectionList<TItem extends ListItem>(
6363
onLayout,
6464
customListHeader,
6565
listHeaderWrapperStyle,
66+
isRowMultilineSupported = false,
6667
}: BaseSelectionListProps<TItem>,
6768
inputRef: ForwardedRef<RNTextInput>,
6869
) {
@@ -293,6 +294,7 @@ function BaseSelectionList<TItem extends ListItem>(
293294
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
294295
rightHandSideComponent={rightHandSideComponent}
295296
keyForList={item.keyForList}
297+
isMultilineSupported={isRowMultilineSupported}
296298
/>
297299
);
298300
};

src/components/SelectionList/RadioListItem.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function RadioListItem({
1616
onDismissError,
1717
shouldPreventDefaultFocusOnSelectRow,
1818
rightHandSideComponent,
19+
isMultilineSupported = false,
1920
}: RadioListItemProps) {
2021
const styles = useThemeStyles();
2122
const StyleUtils = useStyleUtils();
@@ -44,9 +45,10 @@ function RadioListItem({
4445
styles.optionDisplayName,
4546
isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText,
4647
styles.sidebarLinkTextBold,
47-
styles.pre,
48+
isMultilineSupported ? styles.preWrap : styles.pre,
4849
item.alternateText ? styles.mb1 : null,
4950
]}
51+
numberOfLines={isMultilineSupported ? 2 : 1}
5052
/>
5153

5254
{!!item.alternateText && (

src/components/SelectionList/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type CommonListItemProps<TItem> = {
3737

3838
/** Styles for the checkbox wrapper view if select multiple option is on */
3939
selectMultipleStyle?: StyleProp<ViewStyle>;
40+
41+
/** Whether to wrap long text up to 2 lines */
42+
isMultilineSupported?: boolean;
4043
};
4144

4245
type ListItem = {
@@ -83,6 +86,9 @@ type ListItem = {
8386

8487
/** Whether this option should show subscript */
8588
shouldShowSubscript?: boolean;
89+
90+
/** Whether to wrap long text up to 2 lines */
91+
isMultilineSupported?: boolean;
8692
};
8793

8894
type ListItemProps = CommonListItemProps<ListItem> & {
@@ -258,6 +264,9 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
258264

259265
/** Styles for the list header wrapper */
260266
listHeaderWrapperStyle?: StyleProp<ViewStyle>;
267+
268+
/** Whether to wrap long text up to 2 lines */
269+
isRowMultilineSupported?: boolean;
261270
};
262271

263272
type ItemLayout = {

src/components/TextWithTooltip/index.native.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import React from 'react';
22
import Text from '@components/Text';
33
import type TextWithTooltipProps from './types';
44

5-
function TextWithTooltip({text, textStyles}: TextWithTooltipProps) {
5+
function TextWithTooltip({text, textStyles, numberOfLines = 1}: TextWithTooltipProps) {
66
return (
77
<Text
88
style={textStyles}
9-
numberOfLines={1}
9+
numberOfLines={numberOfLines}
1010
>
1111
{text}
1212
</Text>

src/components/TextWithTooltip/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type LayoutChangeEvent = {
77
target: HTMLElement;
88
};
99

10-
function TextWithTooltip({text, shouldShowTooltip, textStyles}: TextWithTooltipProps) {
10+
function TextWithTooltip({text, shouldShowTooltip, textStyles, numberOfLines = 1}: TextWithTooltipProps) {
1111
const [showTooltip, setShowTooltip] = useState(false);
1212

1313
return (
@@ -17,7 +17,7 @@ function TextWithTooltip({text, shouldShowTooltip, textStyles}: TextWithTooltipP
1717
>
1818
<Text
1919
style={textStyles}
20-
numberOfLines={1}
20+
numberOfLines={numberOfLines}
2121
onLayout={(e) => {
2222
const target = (e.nativeEvent as unknown as LayoutChangeEvent).target;
2323
if (!shouldShowTooltip) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import type {StyleProp, TextStyle} from 'react-native';
22

33
type TextWithTooltipProps = {
4+
/** The text to display */
45
text: string;
6+
7+
/** Whether to show the toolip text */
58
shouldShowTooltip: boolean;
9+
10+
/** Additional text styles */
611
textStyles?: StyleProp<TextStyle>;
12+
13+
/** Custom number of lines for text wrapping */
14+
numberOfLines?: number;
715
};
816

917
export default TextWithTooltipProps;

0 commit comments

Comments
 (0)