Skip to content

Commit

Permalink
Merge pull request #37389 from neonbhai/selection-list-multiline-fix
Browse files Browse the repository at this point in the history
[Categories] Add support for long category names
  • Loading branch information
puneetlath authored Feb 28, 2024
2 parents 3100b18 + a3334e7 commit b384904
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/CategoryPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function CategoryPicker({selectedCategory, policyCategories, policyRecentlyUsedC
onSelectRow={onSubmit}
ListItem={RadioListItem}
initiallyFocusedOptionKey={selectedOptionKey}
isRowMultilineSupported
/>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function BaseSelectionList<TItem extends ListItem>(
onLayout,
customListHeader,
listHeaderWrapperStyle,
isRowMultilineSupported = false,
}: BaseSelectionListProps<TItem>,
inputRef: ForwardedRef<RNTextInput>,
) {
Expand Down Expand Up @@ -293,6 +294,7 @@ function BaseSelectionList<TItem extends ListItem>(
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
rightHandSideComponent={rightHandSideComponent}
keyForList={item.keyForList}
isMultilineSupported={isRowMultilineSupported}
/>
);
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/SelectionList/RadioListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function RadioListItem({
onDismissError,
shouldPreventDefaultFocusOnSelectRow,
rightHandSideComponent,
isMultilineSupported = false,
}: RadioListItemProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -44,9 +45,10 @@ function RadioListItem({
styles.optionDisplayName,
isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText,
styles.sidebarLinkTextBold,
styles.pre,
isMultilineSupported ? styles.preWrap : styles.pre,
item.alternateText ? styles.mb1 : null,
]}
numberOfLines={isMultilineSupported ? 2 : 1}
/>

{!!item.alternateText && (
Expand Down
9 changes: 9 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type CommonListItemProps<TItem> = {

/** Styles for the checkbox wrapper view if select multiple option is on */
selectMultipleStyle?: StyleProp<ViewStyle>;

/** Whether to wrap long text up to 2 lines */
isMultilineSupported?: boolean;
};

type ListItem = {
Expand Down Expand Up @@ -83,6 +86,9 @@ type ListItem = {

/** Whether this option should show subscript */
shouldShowSubscript?: boolean;

/** Whether to wrap long text up to 2 lines */
isMultilineSupported?: boolean;
};

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

/** Styles for the list header wrapper */
listHeaderWrapperStyle?: StyleProp<ViewStyle>;

/** Whether to wrap long text up to 2 lines */
isRowMultilineSupported?: boolean;
};

type ItemLayout = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextWithTooltip/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react';
import Text from '@components/Text';
import type TextWithTooltipProps from './types';

function TextWithTooltip({text, textStyles}: TextWithTooltipProps) {
function TextWithTooltip({text, textStyles, numberOfLines = 1}: TextWithTooltipProps) {
return (
<Text
style={textStyles}
numberOfLines={1}
numberOfLines={numberOfLines}
>
{text}
</Text>
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextWithTooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type LayoutChangeEvent = {
target: HTMLElement;
};

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

return (
Expand All @@ -17,7 +17,7 @@ function TextWithTooltip({text, shouldShowTooltip, textStyles}: TextWithTooltipP
>
<Text
style={textStyles}
numberOfLines={1}
numberOfLines={numberOfLines}
onLayout={(e) => {
const target = (e.nativeEvent as unknown as LayoutChangeEvent).target;
if (!shouldShowTooltip) {
Expand Down
8 changes: 8 additions & 0 deletions src/components/TextWithTooltip/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import type {StyleProp, TextStyle} from 'react-native';

type TextWithTooltipProps = {
/** The text to display */
text: string;

/** Whether to show the toolip text */
shouldShowTooltip: boolean;

/** Additional text styles */
textStyles?: StyleProp<TextStyle>;

/** Custom number of lines for text wrapping */
numberOfLines?: number;
};

export default TextWithTooltipProps;

0 comments on commit b384904

Please sign in to comment.