Skip to content

Commit f4440fa

Browse files
committed
fix(components,-protocol-designer): fix lineclamp for dropdown menu
According to designs, the main text for a dropdown option should be clamped to 3 lines maximum. In the event that only one option is produced in DropDownStepFormField, the line clamp should also apply to the returned styled text. Closes RQA-3945
1 parent 78848e5 commit f4440fa

File tree

2 files changed

+19
-6
lines changed
  • components/src/molecules/DropdownMenu
  • protocol-designer/src/molecules/DropdownStepFormField

2 files changed

+19
-6
lines changed

components/src/molecules/DropdownMenu/index.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { LiquidIcon } from '../LiquidIcon'
2727
import { DeckInfoLabel } from '../DeckInfoLabel'
2828

2929
import type { FocusEventHandler } from 'react'
30+
import type { FlattenSimpleInterpolation } from 'styled-components'
3031

3132
export interface DropdownOption {
3233
name: string
@@ -268,7 +269,7 @@ export function DropdownMenu(props: DropdownMenuProps): JSX.Element {
268269
>
269270
<StyledText
270271
desktopStyle="captionRegular"
271-
css={LINE_CLAMP_TEXT_STYLE}
272+
css={LINE_CLAMP_TEXT_STYLE(1)}
272273
>
273274
{currentOption.name}
274275
</StyledText>
@@ -327,7 +328,10 @@ export function DropdownMenu(props: DropdownMenuProps): JSX.Element {
327328
flexDirection={DIRECTION_COLUMN}
328329
gridGap={option.subtext != null ? SPACING.spacing4 : '0'}
329330
>
330-
<StyledText desktopStyle="captionRegular">
331+
<StyledText
332+
desktopStyle="captionRegular"
333+
css={LINE_CLAMP_TEXT_STYLE(3)}
334+
>
331335
{option.name}
332336
</StyledText>
333337
<StyledText
@@ -363,12 +367,17 @@ export function DropdownMenu(props: DropdownMenuProps): JSX.Element {
363367
)
364368
}
365369

366-
const LINE_CLAMP_TEXT_STYLE = css`
370+
export const LINE_CLAMP_TEXT_STYLE = (
371+
lineClamp?: number,
372+
title?: boolean
373+
): FlattenSimpleInterpolation => css`
367374
display: -webkit-box;
368375
-webkit-box-orient: vertical;
369376
overflow: ${OVERFLOW_HIDDEN};
370377
text-overflow: ellipsis;
371378
word-wrap: break-word;
372-
-webkit-line-clamp: 1;
373-
word-break: break-all;
379+
-webkit-line-clamp: ${lineClamp ?? 1};
380+
word-break: ${title === true
381+
? 'normal'
382+
: 'break-all'}; // normal for tile and break-all for a non word case like aaaaaaaa
374383
`

protocol-designer/src/molecules/DropdownStepFormField/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DeckInfoLabel,
88
DropdownMenu,
99
Flex,
10+
LINE_CLAMP_TEXT_STYLE,
1011
ListItem,
1112
SPACING,
1213
StyledText,
@@ -122,7 +123,10 @@ export function DropdownStepFormField(
122123
flexDirection={DIRECTION_COLUMN}
123124
gridGap={options[0].subtext != null ? SPACING.spacing4 : '0'}
124125
>
125-
<StyledText desktopStyle="captionRegular">
126+
<StyledText
127+
desktopStyle="captionRegular"
128+
css={LINE_CLAMP_TEXT_STYLE(3)}
129+
>
126130
{options[0].name}
127131
</StyledText>
128132
<StyledText

0 commit comments

Comments
 (0)