Skip to content

New web component ol-chip#12012

Open
lokesh wants to merge 29 commits intointernetarchive:masterfrom
lokesh:web-component-chip
Open

New web component ol-chip#12012
lokesh wants to merge 29 commits intointernetarchive:masterfrom
lokesh:web-component-chip

Conversation

@lokesh
Copy link
Collaborator

@lokesh lokesh commented Mar 5, 2026

tag.mp4

This makes progress on both the following tasks:

  1. Standardize Subject Tags UX - Standardize Subject Tags UX using BEM CSS #11728
  2. Revamp of the search and facets UI w/focus on mobile

Adds an ol-chip web component and uses it to replace the plain text/link facets on search results pages and the related subjects section on subject pages.

To limit scope, a follow-up PR will be used to replace other tags/chips and remove old code.

Changes

New components:

  • OLChip — A pill-shaped interactive chip that supports selected state (with checkmark icon), optional count badge, link mode (href), small/medium sizes, and accessible labels via chip-label prop. Fires ol-chip-select event on click.
  • OLChipGroup — A flex-wrap container for consistent chip spacing.

Template updates:

  • Search facets (work_search_facets.html) — Facet entries now render as <ol-chip size="small">
  • Selected facets (work_search_selected_facets.html) — Selected filters render as <ol-chip selected> with accessible chip-label tooltips (e.g. "Written in: English").
  • Related subjects (RelatedSubjects.html) — Subject links wrapped in <ol-chip-group> with small chips.
  • Design pattern library (design.html) — Added chip examples (default, selected, small, with count, as link, interactive toggle). Restructured page with sidebar nav.

Styling & layout:

  • Pre-hydration styles in head.html to prevent layout shift before Lit hydrates.
  • Updated page-design.css with sidebar nav layout for the design pattern library.
  • Minor facet layout fixes in legacy.css and headings.css.

Technical

  • chip-label prop forwards as aria-label to the inner <a>/<button>

Screenshots

image
image
image

Testing

  1. Visit /search?q=dogs — facets in the sidebar should render as small chips
  2. Click a facet — selected facets above results should show as selected chips with ✓ icon
  3. Visit a subject page like /subjects/fiction — related subjects should render as chips
  4. Visit /developers/design — chip examples section should be interactive

Stakeholders

@mekarpeles @cdrini @jimchamp @RayBB

lokesh and others added 24 commits February 12, 2026 22:07
- Imported OLChip component in index.js.
- Replaced span elements with ol-chip components in work_search_facets.html for better UI representation of facet entries.
- Updated work_search_selected_facets.html to use ol-chip for selected facets, enhancing the display and interaction.
- Modified CSS for facets to improve layout and styling, including flex properties for better responsiveness.
- Added import for ol-chip styles in page-user.less to ensure proper styling is applied.
- Renamed event from 'chip-click' to 'ol-chip-select' for clarity.
- Simplified CSS properties in OLChip for consistency and readability.
- Adjusted padding and font sizes in ol-chip.less for better alignment.
- Updated facet template links to use consistent capitalization for "More" and "Less".
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	openlibrary/components/lit/index.js
- Introduced CSS variables for padding and icon sizes in OLChip for improved customization.
- Updated styles for selected state and small size variations to enhance visual consistency.
- Added comprehensive examples and documentation for the OLChip component in design.html, showcasing various use cases including default, selected, small size, and interactive toggle functionalities.
- Changed the color of the selected state in the OLChip component for better visibility.
- Removed unused small size examples from design.html to streamline the documentation and improve clarity.
- Added positioning and padding adjustments in legacy.less for better layout consistency.
…tion

- Changed the event name from 'update:page' to 'ol-pagination-change' in the OlPagination component for better clarity and consistency.
- Updated the event detail structure to include an object with the page number.
- Revised design.html to reflect the new event name in examples, improving documentation accuracy.
- Enhanced CSS styles in page-design.less for better layout and spacing in the design pattern library.
- Modified the condition for skipping empty facet counts to improve performance.
- Introduced tooltips for facets in the selected facets template to enhance user experience.
- Added a comment regarding the handling of the 'public_scan_b' facet for future consideration.
- Introduced the OLChipGroup component to enhance the grouping of chips in the UI.
- Updated the RelatedSubjects macro to utilize OLChipGroup for better visual organization of subject links.
- Imported the new OLChip component styles in the page-subject.less file for consistent styling.
- Port facet layout changes (flex, gap) from legacy.less to legacy.css
- Port h4.facetHead styling (inline-flex, .facet-icon) from headings.less to headings.css
- Convert page-design.css from LESS syntax to native CSS (flat selectors, CSS custom properties)
- Create ol-chip.css from ol-chip.less and add imports to page-subject.css and page-user.css
- Resolve all merge conflicts from LESS-to-CSS migration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The facet tooltips (e.g. "Written in", "Published by") were set via
the title attribute on the host element, which screen readers can't
reach inside shadow DOM. Add a chip-label property that forwards as
aria-label to the inner <a>/<button>, so assistive tech announces
the full context like "Written in: English".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Modify .stylelintrc.json to allow specific ol- types in selector-type-no-unknown rule.
- Remove unused import for ol-chip.css in page-user.css to streamline styles.
- Change color property in h4.facetHead from a hex value to a CSS variable for better maintainability.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ct.css. Add pre-hydration styles for ol-chip and ol-read-more components in head.html to prevent layout shifts.
- Consolidate check and close icons into a single _renderIcons method.
- Update CSS class names for icons to improve clarity and maintainability.
- Implement hover effects to toggle icon visibility based on chip selection state.
…hover effects

- Rename CSS classes for clarity, changing .icon to .icon-slot and introducing .icon-carousel.
- Implement a carousel effect for icons on hover, enhancing user interaction.
- Adjust icon visibility and transitions to create a smoother experience when selecting the chip.
- Add a new section on compound components in web-components.md to clarify usage and best practices.
- Update README.md to include a link to the new design documentation.
- Refine OLChip styles to improve hover effects and responsiveness, ensuring better user interaction across devices.
- Update tooltip translations in work_search_selected_facets.html for improved accessibility.
These changes now live in dedicated branches for smaller PRs:
- docs/ai/ updates → ai-design branch
- OlPagination event rename → pagination-event branch

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lokesh lokesh marked this pull request as ready for review March 11, 2026 18:42
@lokesh lokesh requested a review from mekarpeles March 11, 2026 18:50
@lokesh lokesh changed the title Web component chip New web component ol-chip Mar 11, 2026
- Modified the search form in work_search.html to include an additional class 'search-row'.
- Added CSS rules for the 'search-row' class to provide a margin-bottom of 8px for better spacing.
@lokesh lokesh requested a review from cdrini March 17, 2026 02:21
…t and will-change, scope p rule

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
href: { type: String },
count: { type: String },
chipLabel: { type: String, attribute: 'chip-label' },
accessibleLabel: { type: String, attribute: 'accessible-label' },
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why accessible-label instead of aria-label?

Native HTML attributes should always behave predictably on custom elements — aria-label on a host element should apply to that element, not get silently forwarded to an inner child. Using a distinct prop name makes it clear this is custom behavior that targets the <a> or <button> inside the shadow DOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants