Skip to content

Commit

Permalink
fix(ActionList): do not truncate description by default (#5169)
Browse files Browse the repository at this point in the history
* fix(ActionList): do not truncate description by default

* docs(Description): document new truncate prop

* Create cyan-lions-itch.md

* test(vrt): update snapshots

* fix(ActionList): only break word on label if no inline description

* test(vrt): update snapshots

* test: reproduce overlay issue

* Revert "test: reproduce overlay issue"

This reverts commit c6c2ec5.

---------

Co-authored-by: francinelucca <[email protected]>
  • Loading branch information
francinelucca and francinelucca authored Nov 12, 2024
1 parent 30fa3cc commit a2efba0
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-lions-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

fix(ActionList): do not truncate description by default
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions packages/react/src/ActionList/ActionList.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@
"type": "string | undefined",
"defaultValue": "",
"description": "CSS string"
},
{
"name": "truncate",
"type": "boolean",
"defaultValue": "false",
"description": "Whether the inline description should truncate the text on overflow."
}
]
},
Expand Down
14 changes: 13 additions & 1 deletion packages/react/src/ActionList/ActionList.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,19 @@ export const TextWrapAndTruncation = () => (
<ArrowRightIcon />
</ActionList.LeadingVisual>
Inline Description
<ActionList.Description>This description gets truncated because it is inline</ActionList.Description>
<ActionList.Description truncate>
This description gets truncated because it is inline with truncation
</ActionList.Description>
<ActionList.TrailingVisual>
<ArrowLeftIcon />
</ActionList.TrailingVisual>
</ActionList.Item>
<ActionList.Item>
<ActionList.LeadingVisual>
<ArrowRightIcon />
</ActionList.LeadingVisual>
Inline Description
<ActionList.Description>This description wraps because it is inline without truncation</ActionList.Description>
<ActionList.TrailingVisual>
<ArrowLeftIcon />
</ActionList.TrailingVisual>
Expand Down
48 changes: 48 additions & 0 deletions packages/react/src/ActionList/ActionList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,52 @@ describe('ActionList', () => {
await userEvent.keyboard('{ArrowUp}')
expect(document.activeElement).toHaveTextContent('Option 4')
})

describe('ActionList.Description', () => {
it('should render the description as inline without truncation by default', () => {
const {getByText} = HTMLRender(
<ActionList>
<ActionList.Item>
Item 1<ActionList.Description>Item 1 description</ActionList.Description>
</ActionList.Item>
</ActionList>,
)

const description = getByText('Item 1 description')
expect(description.tagName).toBe('SPAN')
expect(description).toHaveStyleRule('flex-basis', 'auto')
expect(description).not.toHaveStyleRule('overflow', 'ellipsis')
expect(description).not.toHaveStyleRule('white-space', 'nowrap')
})
it('should render the description as `Truncate` when truncate is true', () => {
const {getByText} = HTMLRender(
<ActionList>
<ActionList.Item>
Item 1<ActionList.Description truncate>Item 1 description</ActionList.Description>
</ActionList.Item>
</ActionList>,
)

const description = getByText('Item 1 description')
expect(description.tagName).toBe('DIV')
expect(description).toHaveAttribute('title', 'Item 1 description')
expect(description).toHaveStyleRule('flex-basis', '0')
expect(description).toHaveStyleRule('text-overflow', 'ellipsis')
expect(description).toHaveStyleRule('overflow', 'hidden')
expect(description).toHaveStyleRule('white-space', 'nowrap')
})
it('should render the description in a new line when variant is block', () => {
const {getByText} = HTMLRender(
<ActionList>
<ActionList.Item>
Item 1<ActionList.Description variant="block">Item 1 description</ActionList.Description>
</ActionList.Item>
</ActionList>,
)

const description = getByText('Item 1 description')
expect(description.tagName).toBe('SPAN')
expect(description.parentElement).toHaveAttribute('data-component', 'ActionList.Item--DividerContainer')
})
})
})
11 changes: 8 additions & 3 deletions packages/react/src/ActionList/Description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,24 @@ export type ActionListDescriptionProps = {
*/
variant?: 'inline' | 'block'
className?: string
/**
* Whether the inline description should truncate the text on overflow.
*/
truncate?: boolean
} & SxProp

export const Description: React.FC<React.PropsWithChildren<ActionListDescriptionProps>> = ({
variant = 'inline',
sx = {},
className,
truncate,
...props
}) => {
const styles = {
fontSize: 0,
lineHeight: '16px',
flexGrow: 1,
flexBasis: 0,
flexBasis: variant === 'inline' && !truncate ? 'auto' : 0,
minWidth: 0,
marginLeft: variant === 'block' ? 0 : 2,
color: 'fg.muted',
Expand All @@ -37,11 +42,11 @@ export const Description: React.FC<React.PropsWithChildren<ActionListDescription

const {blockDescriptionId, inlineDescriptionId} = React.useContext(ItemContext)

return variant === 'block' ? (
return variant === 'block' || !truncate ? (
<Box
as="span"
sx={merge(styles, sx as SxProp)}
id={blockDescriptionId}
id={variant === 'block' ? blockDescriptionId : inlineDescriptionId}
className={className}
data-component="ActionList.Description"
>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/ActionList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
flexGrow: slots.inlineDescription ? 0 : 1,
fontWeight: slots.inlineDescription || slots.blockDescription || active ? 'bold' : 'normal',
marginBlockEnd: slots.blockDescription ? '4px' : undefined,
wordBreak: 'break-word',
wordBreak: slots.inlineDescription ? 'normal' : 'break-word',
}}
>
{childrenWithoutSlots}
Expand Down

0 comments on commit a2efba0

Please sign in to comment.