Repository navigation
WIP: fix(ui): wrap long verse action labels without breaking bar alignment - #516
cameronapak wants to merge 1 commit into
Conversation
A host's custom verse action label stayed on one line, so a long or translated label widened its button. At narrow widths it wrapped anyway, and the centered row then dropped every other icon and the swatches. Labels now wrap to two balanced lines inside an 8rem cap, with an ellipsis and a hover title for longer host text. The button measures its longest visible line so it hugs the text and the gaps match one-line actions. The row top-aligns, and the swatches and divider center on a one-line button, so a taller button grows downward and the default bar is unchanged. Labels take their own direction, and buttons keep a 44px minimum width. A Storybook story renders the default, demo, and worst-case label sets. Signed-off-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a2384a-252f-7574-8248-b01487dc3dd7
🦋 Changeset detectedLatest commit: d3d66f1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| const lines = Array.from(range.getClientRects()) | ||
| .filter((line) => line.top < bottom) | ||
| .map((line) => line.width); | ||
| if (lines.length < 2) return; | ||
| const widest = (Math.max(...lines) * element.offsetWidth) / width; | ||
| const fontSize = Number.parseFloat(getComputedStyle(element).fontSize); | ||
| element.style.inlineSize = `${Math.ceil(widest) / fontSize}em`; |
There was a problem hiding this comment.
Mixed-direction labels shrink too far
Range.getClientRects() can return several text fragments for one line when a custom label mixes Arabic or Hebrew with Latin text. Taking the widest fragment makes inlineSize smaller than the complete line. Even a short label such as “حفظ في Notes” can then wrap unnecessarily or lose text to the two-line clamp.
Group fragments by their vertical position and measure each complete line before shrinking the label. Add a mixed-direction label to the story.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ui/src/components/verse-action-popover.tsx
Line: 226-232
Comment:
**Mixed-direction labels shrink too far**
`Range.getClientRects()` can return several text fragments for one line when a custom label mixes Arabic or Hebrew with Latin text. Taking the widest fragment makes `inlineSize` smaller than the complete line. Even a short label such as “حفظ في Notes” can then wrap unnecessarily or lose text to the two-line clamp.
Group fragments by their vertical position and measure each complete line before shrinking the label. Add a mixed-direction label to the story.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
New here? Start here
What's this? Apps can add their own buttons to the verse action bar (the pill with highlight swatches, Copy, and Share that appears when a reader taps a verse) through
verseActionItems. This PR makes long labels on those buttons wrap to two lines cleanly, instead of stretching one button across the bar.Why does it matter? Apps pass labels in their own language, and some will be long, such as German compounds or descriptive actions. Today a long label widens its button, and at narrow widths it wraps anyway. When it wraps, the row stays vertically centered, so every other icon and the swatches drop out of line.
Who does it affect? End users of apps that pass custom
verseActionItems. The default bar, which most apps show, looks the same.What happens if we leave this as-is? Long custom labels keep producing very wide buttons. At narrow widths, such as a 320px phone, they keep misaligning the bar.
Before / after
All captures use the new
Components/VerseActionPopoverstory with the worst-case labels (a German compound, Vietnamese, a long English action, and "Pin"), passed throughactionItems. Each image showsmainon top and this PR below.Phone, 390px: scrolling the whole bar. Before, each label stays on one line, so the bar scrolls about 800px. After, long labels wrap to two lines, the strip scrolls about 460px, and every icon stays level. MP4 version
Desktop, 1298px. Before, the bar is 1188px wide and one button is 331px. After, the bar is 829px wide and the widest button is 128px.
Phone, 320px. Before, the long English label wraps on its own, and the centered row pushes every other icon and the swatches 8px down. After, the label is clamped to two lines and the icons stay level.
RTL and dark mode, 390px, Arabic UI. After, the English label keeps its own direction, so the ellipsis sits at the end of the text.
Default bar, 390px (no custom items, what most apps show). Unchanged.
What changed
titlewith the full label, and the accessible name already carries it.em, so it holds under zoom and larger text. It re-measures when web fonts finish loading and does nothing without layout (jsdom).dir="auto", so an English label in an RTL UI puts its ellipsis at the end. Buttons keep a 44px minimum width, matching the Swift SDK'sminWidth: 44, so a label like "Pin" still gives a full-size target.The Swift SDK (
BibleReaderDrawer) never wraps: labels stay on one line in a horizontal scroll strip. This PR keeps that scroll strip and adds wrapping on web, where custom labels come from the host.Verification
Components/VerseActionPopoverwithDefaultandLongCustomLabels. Adatacontrol switches between the default, demo, and worst-case label sets, all passed throughactionItems. The worst case mixes a German compound, a Vietnamese label with stacked diacritics, a long English action, and "Pin".LongCustomLabelshas anintegrationplay test. It checks that the long label is two lines, that its box is within 1px of its widest visible line, that all icons share one center, and that the swatches center on a one-line button. It fails onmain("expected 16 to be 32") and passes here.main, the long label wrapped and pushed every other icon 8px down.pnpm lint, the UI typecheck, all 681 UI unit tests, and 44 Storybook journeys pass (the new story, the verse action popover shadow stories, and the Bible reader and notes stories).Not changed
100vw - 24pxcap excludes the bar'spx-4padding, because only the custom-items mode setsbox-border. This happens onmaintoo.Confidence Score: 4/5

The PR appears safe to merge, with a non-blocking display issue for mixed-direction custom labels.
Findings
Fix with agent prompt
Summary
This PR caps action-button widths, wraps labels to two lines, and keeps icons and highlight colors aligned.
Reviews (1) · Last reviewed commit: "fix(ui): wrap long verse action labels w..." · Reviewed by Greptile