Skip to content

feat: Add 'Read More' - PART 2#11682

Merged
cdrini merged 23 commits intointernetarchive:masterfrom
lokesh:feat/web-component-read-more-part-2
Feb 3, 2026
Merged

feat: Add 'Read More' - PART 2#11682
cdrini merged 23 commits intointernetarchive:masterfrom
lokesh:feat/web-component-read-more-part-2

Conversation

@lokesh
Copy link
Copy Markdown
Collaborator

@lokesh lokesh commented Jan 8, 2026

Continuation of the work done in #11666

This PR finishes replacing all instances of the Read More feature with the new web component. It also removes the code related to the old component.

Technical

Extends usage to additional locations:

  • Table of Contents and Work description in edition view
  • Chapter highlights in search results

Removes old Read More implementation:

  • Deleted openlibrary/macros/ReadMore.html macro
  • Deleted static/css/components/read-more.less styles
  • Deleted openlibrary/plugins/openlibrary/js/readmore.js component
  • Deleted tests/unit/js/readmore.test.js tests

Testing

  1. Navigate to an edition page with a long description (e.g., /books/OL...)
  • Verify description is truncated to ~4 lines with "Read More" button
  • Click to expand/collapse, confirm toggle works
  1. Navigate to an edition page with a Table of Contents
  • Verify TOC is truncated with "Read More" button when content exceeds 200px
  • Toggle to expand/collapse

Screenshot

Frame 427318911

Stakeholders

@RayBB @mekarpeles @cdrini @jimchamp

lokesh and others added 17 commits January 5, 2026 13:05
…e and package.json; update package-lock.json to include lit dependencies.
- Introduced a new web component, OLReadMore, that supports height-based and line-based truncation.
- Updated index.js to import the new component for registration as a custom element.
- Included the new OL components script in the footer for enhanced functionality.
- Replaced the existing book description implementation with the OLReadMore component for better user experience with expandable/collapsible content.
- Changed 'Read more' and 'Read less' to 'Read More' and 'Read Less' for uniformity in capitalization.
- Removed unnecessary margin-left style from the chevron icon.
- Changed 'Read more' and 'Read less' to 'Read More' and 'Read Less' for uniformity in capitalization in the book description section.
…oved accessibility and functionality

- Replaced button elements with <details> and <summary> for better semantic structure.
- Updated styles for toggle behavior and chevron icon.
- Simplified the logic for handling content expansion and truncation.
- Enhanced user experience by managing scroll behavior when collapsing content.
- Changed the Vite configuration file reference in the Makefile and package.json from `lit-vite.config.js` to `vite-lit.config.mjs`.
- Removed the obsolete `lit-vite.config.js` file.
- Updated the new Vite configuration file to include a comment indicating its purpose for Vue components.
…ling

- Replaced <details> and <summary> elements with button elements for improved control over expansion and collapse.
- Updated CSS class names for clarity and consistency.
- Simplified event handling for toggling content visibility.
- Enhanced button styles and added hover effects for better user interaction.
…ttribute to chevron icon

- Updated the chevron SVG icon in the OLReadMore component to include the aria-hidden attribute for improved screen reader compatibility.
…experience

- Updated the Table of Contents section to use the ol-read-more component for better expansion and collapse functionality.
- Adjusted CSS styles for toc entries, including font size and padding for enhanced readability.
- Improved the visual appearance of the toc__dots with a more defined border color.
… component

- Replaced the previous work description structure with the ol-read-more component for improved readability and user interaction.
- Adjusted the maximum lines displayed and updated the text for expanding and collapsing the description.
…mponent

- Replaced the existing chapter display structure with the ol-read-more component for improved readability and user interaction.
- Maintained functionality for displaying chapter links and pagination while enhancing the overall user experience.
- Deleted the ReadMore.html macro and its corresponding CSS styles from the project.
- Updated LESS files to remove references to the read-more component, streamlining the codebase.
- Deleted the ReadMoreComponent and its related JavaScript and CSS files to streamline the codebase.
- Updated the index.js file to remove conditional loading of read-more components.
- Adjusted HTML templates to eliminate references to the read-more functionality, enhancing overall clarity and maintainability.
lokesh added 4 commits January 8, 2026 13:54
…template

- Deleted the ReadMore entry from bundlesize.config.json to streamline bundle size checks.
- Updated the edition view template to remove the ReadMore class from excerpts, enhancing clarity and maintainability.
@lokesh lokesh requested a review from cdrini January 30, 2026 18:36
Copy link
Copy Markdown
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing some blocking issues for the TOC on the search page:

image

https://testing.openlibrary.org/search?q=java+tree&mode=everything

Before:

image

I like the idea of making the leader dots in the TOC lighter; it makes the overall page look much cleaner! There's still something a bit funny about this UX; it's causing my eyes to strain when I see it; causing a kind of funny visual banding effect on desktop. It's a bit more accentuated now that the font size is smaller and the lines are fainter. Not sure what solution is! Not a blocker.

@lokesh
Copy link
Copy Markdown
Collaborator Author

lokesh commented Jan 30, 2026

@cdrini the Search ToC primary issue that you are referring to is the background color of the new Read More component?

@github-actions github-actions bot added the Needs: Response Issues which require feedback from lead label Jan 31, 2026
@cdrini
Copy link
Copy Markdown
Collaborator

cdrini commented Feb 3, 2026

Yes exactly! It should look like the original designs, the change in colours/font size/padding make it look broken currently. TOC in search is a new feature that was just recently released, so we need to be more mindful of regressions, to make sure we lead with our best foot forward. It's also a great case-study in some of the difficulties that web component CSS isolation causes ; we do want our web components to support being styled to match their context. We should be able to achieve the same UI with adding some ::parts to the read more component or css custom props.

@cdrini cdrini removed the Needs: Response Issues which require feedback from lead label Feb 3, 2026
- Added new properties: background-color, label-size, and padding-left for improved customization of the OLReadMore component.
- Updated the component's internal styles and logic to accommodate these new properties.
- Modified example usage in SearchResultsWork.html to demonstrate the new attributes.
@lokesh
Copy link
Copy Markdown
Collaborator Author

lokesh commented Feb 3, 2026

Fixed rendering:
image

It's also a great case-study in some of the difficulties that web component CSS isolation causes ; we do want our web components to support being styled to match their context. We should be able to achieve the same UI with adding some ::parts to the read more component or css custom props.

I've added additional properties to support this variant of the component. In general, I'd lean into properties over exposing ::parts, though the latter could be useful in some instances. But one of the big benefits of web components is predictability of rendering, and allowing devs to arbitrarily style and tinker exposes us to maintenance challenges. Better to start as narrow as possible as it is easy to add features, but they are hard to remove.

@lokesh lokesh requested a review from cdrini February 3, 2026 19:10
Copy link
Copy Markdown
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice lgtm! Merging as-is, but I think we might want to brainstorm about the styling interface during our call a bit. Also there's one small non-blocking bug with the TOC in search when in librarian mode, where clicking "show more" causes the search item card to become selected. I think the code was previously ignoring clicks on anchor elements.

This looks great!! 🥳 Love all the deleted/DRY'd up code!

Comment on lines +30 to +32
backgroundColor: { type: String, attribute: 'background-color' },
labelSize: { type: String, attribute: 'label-size' },
paddingLeft: { type: String, attribute: 'padding-left' },
Copy link
Copy Markdown
Collaborator

@cdrini cdrini Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not keen on these being separate properties on the web component (eg <ol-read-more padding-left="4px">); that's a pattern I haven't seen anywhere before. It blurs the separation between styling and html content, and adds a decent amount of JS for stuff like parsing values, and creates a syntax slightly separate from CSS that consumers have to learn per-component. Not a blocker, but I think this is something we might want to discuss on Friday to get folks' thoughts on. CC @RayBB

Patterns I have seen elsewhere (eg PrimeVue, webawesome) are:

CSS custom properties are the public interface

<ol-read-more style="--ol-read-more-pading-left: 4px"></ol-read-more>

Or

ol-read-more {
    --ol-read-more-padding-left: 4px;
}

CSS parts are the public interface

ol-read-more::part(toggle-btn) {
    padding-left: 4px;
}

I'm partial to using custom properties for themeing/styling that applies everywhere, and exposing every "chunk" of a component as a ::part for further config. I think that strikes a good compromise between having controlled interfaces where we can easily make updates to a component's internals without having to maintain a huge public API / breaking clients, while also allowing clients to configure the component without them having to modify the component every time a new use case pops up to expose new hooks. A balance of flexibility and rigidity/brittleness.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdrini thanks for sharing alternative directions as it illuminates the deficiencies with the padding left property. I think the css ::part is prob the right approach.

I'll get a PR ready ahead of our meeting week, it will also be a good opportunity to discuss our strategy for when to expose these css hooks . Our strategy doesn't have be to perfect, as web component usage is minimal in the codebase, and we have time to dial it in as we learn through experience. Thanks again for the feedback.

@cdrini cdrini merged commit 8daa11b into internetarchive:master Feb 3, 2026
5 checks passed
@cdrini cdrini assigned cdrini and unassigned mekarpeles Feb 3, 2026
@RayBB
Copy link
Copy Markdown
Collaborator

RayBB commented Feb 3, 2026

@lokesh what a huge win! I love seeing a PR like this knocking out hundreds of old lines of code.

Excited to see what's next!

lokesh added a commit to lokesh/openlibrary that referenced this pull request Feb 4, 2026
* Enhance build process by adding support for lit-components in Makefile and package.json; update package-lock.json to include lit dependencies.

* Add OLReadMore component for expandable/collapsible content

- Introduced a new web component, OLReadMore, that supports height-based and line-based truncation.
- Updated index.js to import the new component for registration as a custom element.

* Add OL components and update book description rendering

- Included the new OL components script in the footer for enhanced functionality.
- Replaced the existing book description implementation with the OLReadMore component for better user experience with expandable/collapsible content.

* Update OLReadMore component text for consistency

- Changed 'Read more' and 'Read less' to 'Read More' and 'Read Less' for uniformity in capitalization.
- Removed unnecessary margin-left style from the chevron icon.

* Update capitalization of OLReadMore component text for consistency

- Changed 'Read more' and 'Read less' to 'Read More' and 'Read Less' for uniformity in capitalization in the book description section.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor OLReadMore component to use <details> and <summary> for improved accessibility and functionality

- Replaced button elements with <details> and <summary> for better semantic structure.
- Updated styles for toggle behavior and chevron icon.
- Simplified the logic for handling content expansion and truncation.
- Enhanced user experience by managing scroll behavior when collapsing content.

* Update build configuration for Lit components

- Changed the Vite configuration file reference in the Makefile and package.json from `lit-vite.config.js` to `vite-lit.config.mjs`.
- Removed the obsolete `lit-vite.config.js` file.
- Updated the new Vite configuration file to include a comment indicating its purpose for Vue components.

* Refactor OLReadMore component to enhance toggle functionality and styling

- Replaced <details> and <summary> elements with button elements for improved control over expansion and collapse.
- Updated CSS class names for clarity and consistency.
- Simplified event handling for toggling content visibility.
- Enhanced button styles and added hover effects for better user interaction.

* Enhance accessibility of OLReadMore component by adding aria-hidden attribute to chevron icon

- Updated the chevron SVG icon in the OLReadMore component to include the aria-hidden attribute for improved screen reader compatibility.

* Refactor Table of Contents display in edition view for improved user experience

- Updated the Table of Contents section to use the ol-read-more component for better expansion and collapse functionality.
- Adjusted CSS styles for toc entries, including font size and padding for enhanced readability.
- Improved the visual appearance of the toc__dots with a more defined border color.

* Refactor work description display in edition view to use ol-read-more component

- Replaced the previous work description structure with the ol-read-more component for improved readability and user interaction.
- Adjusted the maximum lines displayed and updated the text for expanding and collapsing the description.

* Refactor chapter display in search results to utilize ol-read-more component

- Replaced the existing chapter display structure with the ol-read-more component for improved readability and user interaction.
- Maintained functionality for displaying chapter links and pagination while enhancing the overall user experience.

* Remove ol-read-more component and associated styles

- Deleted the ReadMore.html macro and its corresponding CSS styles from the project.
- Updated LESS files to remove references to the read-more component, streamlining the codebase.

* Remove ReadMore component and associated functionality

- Deleted the ReadMoreComponent and its related JavaScript and CSS files to streamline the codebase.
- Updated the index.js file to remove conditional loading of read-more components.
- Adjusted HTML templates to eliminate references to the read-more functionality, enhancing overall clarity and maintainability.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove commented line for line-height in Table of Contents styles

* Update Table of Contents styles to use a lighter grey for the border of dots for improved visual consistency

* Remove ReadMore functionality from bundlesize configuration and HTML template

- Deleted the ReadMore entry from bundlesize.config.json to streamline bundle size checks.
- Updated the edition view template to remove the ReadMore class from excerpts, enhancing clarity and maintainability.

* feat: Enhance OLReadMore component with new properties

- Added new properties: background-color, label-size, and padding-left for improved customization of the OLReadMore component.
- Updated the component's internal styles and logic to accommodate these new properties.
- Modified example usage in SearchResultsWork.html to demonstrate the new attributes.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
bhardwajparth51 added a commit to bhardwajparth51/openlibrary that referenced this pull request Feb 17, 2026
* Enhance build process by adding support for lit-components in Makefile and package.json; update package-lock.json to include lit dependencies.

* Add OLReadMore component for expandable/collapsible content

- Introduced a new web component, OLReadMore, that supports height-based and line-based truncation.
- Updated index.js to import the new component for registration as a custom element.

* Add OL components and update book description rendering

- Included the new OL components script in the footer for enhanced functionality.
- Replaced the existing book description implementation with the OLReadMore component for better user experience with expandable/collapsible content.

* Update OLReadMore component text for consistency

- Changed 'Read more' and 'Read less' to 'Read More' and 'Read Less' for uniformity in capitalization.
- Removed unnecessary margin-left style from the chevron icon.

* Update capitalization of OLReadMore component text for consistency

- Changed 'Read more' and 'Read less' to 'Read More' and 'Read Less' for uniformity in capitalization in the book description section.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor OLReadMore component to use <details> and <summary> for improved accessibility and functionality

- Replaced button elements with <details> and <summary> for better semantic structure.
- Updated styles for toggle behavior and chevron icon.
- Simplified the logic for handling content expansion and truncation.
- Enhanced user experience by managing scroll behavior when collapsing content.

* Update build configuration for Lit components

- Changed the Vite configuration file reference in the Makefile and package.json from `lit-vite.config.js` to `vite-lit.config.mjs`.
- Removed the obsolete `lit-vite.config.js` file.
- Updated the new Vite configuration file to include a comment indicating its purpose for Vue components.

* Refactor OLReadMore component to enhance toggle functionality and styling

- Replaced <details> and <summary> elements with button elements for improved control over expansion and collapse.
- Updated CSS class names for clarity and consistency.
- Simplified event handling for toggling content visibility.
- Enhanced button styles and added hover effects for better user interaction.

* Enhance accessibility of OLReadMore component by adding aria-hidden attribute to chevron icon

- Updated the chevron SVG icon in the OLReadMore component to include the aria-hidden attribute for improved screen reader compatibility.

* Refactor Table of Contents display in edition view for improved user experience

- Updated the Table of Contents section to use the ol-read-more component for better expansion and collapse functionality.
- Adjusted CSS styles for toc entries, including font size and padding for enhanced readability.
- Improved the visual appearance of the toc__dots with a more defined border color.

* Refactor work description display in edition view to use ol-read-more component

- Replaced the previous work description structure with the ol-read-more component for improved readability and user interaction.
- Adjusted the maximum lines displayed and updated the text for expanding and collapsing the description.

* Refactor chapter display in search results to utilize ol-read-more component

- Replaced the existing chapter display structure with the ol-read-more component for improved readability and user interaction.
- Maintained functionality for displaying chapter links and pagination while enhancing the overall user experience.

* Remove ol-read-more component and associated styles

- Deleted the ReadMore.html macro and its corresponding CSS styles from the project.
- Updated LESS files to remove references to the read-more component, streamlining the codebase.

* Remove ReadMore component and associated functionality

- Deleted the ReadMoreComponent and its related JavaScript and CSS files to streamline the codebase.
- Updated the index.js file to remove conditional loading of read-more components.
- Adjusted HTML templates to eliminate references to the read-more functionality, enhancing overall clarity and maintainability.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove commented line for line-height in Table of Contents styles

* Update Table of Contents styles to use a lighter grey for the border of dots for improved visual consistency

* Remove ReadMore functionality from bundlesize configuration and HTML template

- Deleted the ReadMore entry from bundlesize.config.json to streamline bundle size checks.
- Updated the edition view template to remove the ReadMore class from excerpts, enhancing clarity and maintainability.

* feat: Enhance OLReadMore component with new properties

- Added new properties: background-color, label-size, and padding-left for improved customization of the OLReadMore component.
- Updated the component's internal styles and logic to accommodate these new properties.
- Modified example usage in SearchResultsWork.html to demonstrate the new attributes.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

4 participants