Skip to content

Commit

Permalink
Fix: Ensure onTruncate callback is called in ShowMore component
Browse files Browse the repository at this point in the history
The `ShowMore` component had an `onTruncate` prop, but it was not being called when truncation occurred. This commit fixes the issue by invoking the `onTruncate` callback when the content is truncated.
  • Loading branch information
say8425 authored and chengpeiquan committed Jan 3, 2025
1 parent 6c01017 commit f4e221e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ShowMore/ShowMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const ShowMore = forwardRef<ShowMoreRef, ShowMoreProps>(
less = 'Collapse',
anchorClass,
onToggle,
onTruncate,
children,
...rests
},
Expand Down Expand Up @@ -77,7 +78,13 @@ export const ShowMore = forwardRef<ShowMoreRef, ShowMoreProps>(
toggleLines={toggleLines}
/>
}
onTruncate={handleTruncate}
onTruncate={(disTruncate) => {
handleTruncate(disTruncate)

if (!expanded) {
onTruncate?.(disTruncate)
}
}}
>
{children}
</Truncate>
Expand Down

0 comments on commit f4e221e

Please sign in to comment.