diff --git a/src/shared/nested-dropdown-list/list-item.styles.tsx b/src/shared/nested-dropdown-list/list-item.styles.tsx index 042530c2d..dff0eb27f 100644 --- a/src/shared/nested-dropdown-list/list-item.styles.tsx +++ b/src/shared/nested-dropdown-list/list-item.styles.tsx @@ -21,7 +21,7 @@ interface ListItemSelectorProps { $multiSelect: boolean; } -interface LabelProps { +interface TruncateProps { $truncateType?: TruncateType; } @@ -89,7 +89,7 @@ export const Item = styled.li` }} `; -export const Label = styled.div` +export const Label = styled.div` ${TextStyleHelper.getTextStyle("Body", "regular")} overflow: hidden; @@ -182,7 +182,7 @@ export const TriangleIcon = styled(TriangleForwardFillIcon)` color: ${Color.Primary}; `; -export const Title = styled.button` +export const TitleButton = styled.button` ${TextStyleHelper.getTextStyle("H4", "semibold")} color: ${Color.Neutral[1]}; text-align: left; @@ -193,15 +193,24 @@ export const Title = styled.button` cursor: pointer; width: 100%; padding: 0; - overflow-wrap: anywhere; - - span { - overflow: hidden; - display: -webkit-box; - text-overflow: ellipsis; - -webkit-line-clamp: 2; - -webkit-box-orient: vertical; - } + overflow: hidden; +`; + +export const Title = styled.div` + ${(props) => { + switch (props.$truncateType) { + case "middle": + break; + case "end": + default: + return css` + display: -webkit-box; + text-overflow: ellipsis; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + `; + } + }} `; export const List = styled.ul` diff --git a/src/shared/nested-dropdown-list/list-item.tsx b/src/shared/nested-dropdown-list/list-item.tsx index 4f88a3e5c..981e7c728 100644 --- a/src/shared/nested-dropdown-list/list-item.tsx +++ b/src/shared/nested-dropdown-list/list-item.tsx @@ -12,12 +12,15 @@ import { List, ListItemSelector, Title, + TitleButton, TriangleIcon, TruncateContainer, TruncateFirstLine, TruncateSecondLine, } from "./list-item.styles"; +type LabelType = "category" | "label"; + interface ListItemProps { item: CombinedFormattedOptionProps; selectableCategory?: boolean | undefined; @@ -49,6 +52,7 @@ export const ListItem = ({ // CONST, REF, STATE // ============================================================================= const labelRef = useRef(); + const categoryRef = useRef(); // ============================================================================= // EVENT HANDLERS @@ -78,15 +82,20 @@ export const ListItem = ({ // HELPER FUNCTIONS // ============================================================================= const hasExceededContainer = ( - item: CombinedFormattedOptionProps + item: CombinedFormattedOptionProps, + type: LabelType ) => { const displayText = item.label; let widthOfElement = 0; - if (labelRef && labelRef.current) { + if (type === "label" && labelRef && labelRef.current) { widthOfElement = labelRef.current.getBoundingClientRect().width; } + if (type === "category" && categoryRef && categoryRef.current) { + widthOfElement = categoryRef.current.getBoundingClientRect().width; + } + return StringHelper.shouldTruncateToTwoLines( displayText, widthOfElement @@ -203,9 +212,14 @@ export const ListItem = ({ return ( {renderCategoryIcon()} - - <span>{item.label}</span> - + + + {itemTruncationType === "middle" && + hasExceededContainer(item, "category") + ? renderTruncatedText(item) + : item.label} + + ); }; @@ -222,7 +236,7 @@ export const ListItem = ({ )} diff --git a/src/shared/nested-dropdown-list/nested-dropdown-list.tsx b/src/shared/nested-dropdown-list/nested-dropdown-list.tsx index 962558f33..fd2d60162 100644 --- a/src/shared/nested-dropdown-list/nested-dropdown-list.tsx +++ b/src/shared/nested-dropdown-list/nested-dropdown-list.tsx @@ -582,12 +582,6 @@ export const NestedDropdownList = ({ ); }; - /** - TODO: - 16. renderBottomCta - 19. middle truncation - */ - return ( <>