Fixed missing whitespace around <em> highlights in ol-chip#12493
Conversation
…hive#12488) OLChip's .chip uses display: inline-flex, which made each slotted node (text + <em>) a separate flex item, collapsing the whitespace between them. Wrap <slot> in an inline <span class="label"> so the slotted content lays out as a single flex item in a normal inline formatting context, preserving spaces around bolded highlights.
|
Thank you for the PR, @ragini-pandey. @lokesh is assigned to this PR and currently has:
PR triage checklist (maintainers / Pam)
Note This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting. |
There was a problem hiding this comment.
Pull request overview
Fixes missing whitespace around <em> highlights when Solr-highlighted HTML is slotted into ol-chip (subject pills), addressing #12488 by ensuring highlighted text and surrounding text nodes layout as a single flex item.
Changes:
- Wrapes the
<slot>content in a.labelspan so mixed text/<em>highlight nodes render in one inline formatting context within the chip. - Adds
.labelstyling and explanatory comment documenting the flex/whitespace behavior.
Per review: display: inline is redundant on a flex item (which is blockified anyway), and white-space: normal would block callers from inheriting white-space: nowrap onto the chip. The .label wrapper alone is sufficient to make slotted content a single flex item, which is what fixes the whitespace collapse.
There was a problem hiding this comment.
Pull request overview
Fixes missing whitespace in highlighted subject pills by ensuring Solr highlight markup (e.g. Adventure <em>stories</em>) is laid out as a single flex item inside ol-chip, preventing flexbox whitespace-collapsing between separate slotted nodes.
Changes:
- Wraps the chip’s
<slot>in a<span class="label">so all slotted nodes render in one inline formatting context (preserving spaces around<em>). - Adds an in-code comment documenting the flexbox/slot behavior and why no
.labelstyling is applied.


Closes #12488
Fix: restore whitespace around bolded
<em>highlights insideol-chip(subject pills in search results).Technical
OLChip's.chipelement usesdisplay: inline-flex. When Solr highlight HTML such asAdventure <em>stories</em>is slotted into the chip, the slot's assigned nodes — a text node and an<em>element — become separate flex items. Per the CSS Flexbox spec, leading/trailing whitespace inside a flex item is collapsed, so the trailing space in"Adventure "is dropped and the chip renders asAdventurestories(visuallyAdventure**stories**).The fix wraps
<slot>in a single inline<span class="label">so all slotted content forms one flex item, which in turn lays out its own children in a normal inline formatting context. Whitespace between the text and<em>is preserved. The.icon-slotand.countremain separate flex items, so:host([selected])padding/icon positioning is unaffected.The
.labelwrapper deliberately has no associated CSS rule:display: inlinewould be a no-op —<span>is already inline, and flex items are blockified by the flex container regardless.white-space: normalwould block useful inheritance: a caller writingol-chip { white-space: nowrap; }to force a single-line chip would have that value swallowed inside the shadow tree.A code comment in
render()explains the rationale so future readers know why the wrapper exists and why no styling is attached to it.Why not other approaches:
white-space: preon.chipwould preserve the whitespace but also keep newlines/indentation from the source and disable wrapping — undesirable for chip labels.::slotted(*)styling can't add a layout wrapper around the assigned nodes; it can only style each one individually, so it can't collapse them into one flex item.Testing
1. Reproduce the bug in production search results (recommended):
docker compose upAdventure **stories**rather thanAdventure**stories**.2. Quick isolated DOM test (no full stack required):
Save the file below as
openlibrary/components/lit/OLChip.test.html, then serve thelit/folder and open the page:All five chips must render with visible whitespace where applicable. To confirm the fix actually does something, temporarily revert this PR's change (replace
<span class="label"><slot></slot></span>with bare<slot></slot>) and reload — cases 1, 2, 4, 5 will collapse toAdventurestories-style output. Restore the change and the spaces return.OLChip.test.html(paste this content)Cases verified:
Adventure <em>stories</em>AdventurestoriesAdventure stories<em>Adventure</em> storiesAdventurestoriesAdventure storiesFiction(control, no<em>)FictionFiction(unchanged)<em>Adventure</em> and <em>stories</em>AdventureandstoriesAdventure and stories<ol-chip href="#"><em>Adventure</em> stories</ol-chip>(link variant used by search)AdventurestoriesAdventure storiesSelected-state chips (with the close icon) and chips with
countwere also visually checked to ensure the icon position and count spacing did not regress. As an extra sanity check, applyingol-chip { white-space: nowrap; }from outside the component now correctly forces the chip onto a single line — confirming the wrapper does not block useful style inheritance.Screenshot
Before / after screenshots from
/search?q=adventure&mode=everythingto be attached.Stakeholders
@lokesh (Lead: front-end / LIT components) — per the issue's
Lead: @lokeshlabel.@cdrini — author of #12261 which adopted
ol-chipfor subject pills, and of the original report.