close
Skip to content

fix: account for button height in read-more truncation threshold - #13059

Merged
lokesh merged 3 commits into
internetarchive:masterfrom
RsbhThakur:13052/fix/read-more-height
Jun 30, 2026
Merged

fix: account for button height in read-more truncation threshold#13059
lokesh merged 3 commits into
internetarchive:masterfrom
RsbhThakur:13052/fix/read-more-height

Conversation

@RsbhThakur

@RsbhThakur RsbhThakur commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Closes #13052

fix

Implements a robust line height buffer-based approach for the ol-read-more component's truncation logic. This replaces the fragile, absolute height-based truncation checks, ensuring the "Read More" toggle button only displays when collapsing the content saves a meaningful amount of vertical space.

Technical

  • Modified _checkIfTruncationNeeded() in openlibrary/components/lit/OLReadMore.js to calculate overflow thresholds using line-height multiples rather than absolute pixel bounds.
  • Added static BUFFER_LINES = 5 to represent the line buffer. The component only collapses if the hidden height would exceed the visible collapsed height by more than 5 lines (BUFFER_LINES). If collapsing the content would hide 5 lines or less, it is displayed fully with the toggle button hidden, ensuring the collapse always "earns its place".
  • Implemented _getLineHeight(el) to dynamically resolve the computed line-height of the assigned slotted elements, falling back gracefully to fontSize * 1.5 if the CSS line-height evaluates to normal.
  • Updated the Custom Elements Manifest (openlibrary/components/lit/custom-elements.json) to reflect the new component properties.
  • Successfully verified code style and ran all pre-commit linter checks.

Testing

  1. Edit the content of the <ol-read-more max-height="80px"> component in openlibrary/templates/design.html locally (or view any short/medium book description on /books/OL24620876M).
  2. Verify that:
    • For text where the hidden portion is 5 lines or less, the "Read More" button is completely hidden and the content is fully shown.
    • For long text where collapsing it would hide more than 5 lines, the button displays normally and collapses the content to its configured max-height.

@lokesh

lokesh commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Verified locally. LGTM!

@lokesh
lokesh merged commit 9332cb6 into internetarchive:master Jun 30, 2026
4 of 5 checks passed
@RsbhThakur
RsbhThakur deleted the 13052/fix/read-more-height branch June 30, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't show "Read more" if the read more link takes more room than showing the content

2 participants