Skip to content

Commit

Permalink
Merge pull request #4901 from thematters/revert-4900-feat/expandable-…
Browse files Browse the repository at this point in the history
…empty

Revert "feat(expandable): collapse empty last paragraph"
  • Loading branch information
gitwoz authored Oct 17, 2024
2 parents f708b10 + 224a6f5 commit 2b00766
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/components/Expandable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const calculateContentHeight = (
export const Expandable: React.FC<ExpandableProps> = ({
children,
content,
limit: _limit = 3,
limit = 3,
buffer = 0,
color,
size,
Expand All @@ -91,7 +91,6 @@ export const Expandable: React.FC<ExpandableProps> = ({
const [isOverFlowing, setIsOverFlowing] = useState(false)
const [isExpanded, setIsExpanded] = useState(true)
const [isRichShow, setIsRichShow] = useState(_isRichShow)
const [limit, setLimit] = useState(_limit)
const node: React.RefObject<HTMLParagraphElement> | null = useRef(null)
const collapsedContent = stripHtml(content || '')

Expand Down Expand Up @@ -146,18 +145,7 @@ export const Expandable: React.FC<ExpandableProps> = ({
.getPropertyValue('line-height')
const lines = Math.max(Math.ceil(height / parseFloat(lineHeight)), 0)

// Check if the last paragraph is empty
const paragraphs = element.querySelectorAll('p')
const lastParagraph = paragraphs[Math.min(paragraphs.length - 1, limit - 1)]
const isLastParagraphEmpty =
lastParagraph && lastParagraph.textContent?.trim() === ''

// Adjust the limit if the last paragraph is empty
const adjustedLimit = isLastParagraphEmpty ? limit - 1 : limit

setLimit(adjustedLimit)

if (lines > adjustedLimit + buffer) {
if (lines > limit + buffer) {
setIsOverFlowing(true)
setIsExpanded(false)
}
Expand Down

0 comments on commit 2b00766

Please sign in to comment.