(null);
+ return (
+
+
+ In the beginning was the Word.
+
+ {}}
+ activeHighlights={new Set()}
+ selectedVerses={[1]}
+ highlightedVerses={{}}
+ anchorElement={anchor}
+ actionItems={DATASETS[data]}
+ includeSave
+ onHighlight={() => {}}
+ onClearHighlight={() => {}}
+ onSave={() => {}}
+ onCopy={() => {}}
+ onShare={() => {}}
+ theme={theme}
+ />
+
+ );
+}
+
+const meta = {
+ title: 'Components/VerseActionPopover',
+ component: VerseActionLabels,
+ parameters: { layout: 'centered' },
+ argTypes: {
+ data: {
+ control: 'inline-radio',
+ options: Object.keys(DATASETS),
+ description: 'Action items passed through `actionItems`.',
+ },
+ },
+ render: (args, { globals }) => (
+
+ ),
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj;
+
+/** Built-in actions only, as most apps show the bar. */
+export const Default: Story = { args: { data: 'default' } };
+
+/** Long, translated, and very short host labels side by side. */
+export const LongCustomLabels: Story = {
+ tags: ['integration'],
+ args: { data: 'worstCase' },
+ play: async ({ canvasElement }) => {
+ const dialog = await within(canvasElement.ownerDocument.body).findByRole('dialog', {
+ name: 'Verse actions',
+ });
+ await Promise.all(dialog.getAnimations().map((animation) => animation.finished));
+ const actions = within(dialog);
+ const centerY = (element: Element) => {
+ const { top, height } = element.getBoundingClientRect();
+ return top + height / 2;
+ };
+ const copy = actions.getByRole('button', { name: 'Copy' });
+ const discussion = actions.getByRole('button', {
+ name: 'Add these verses to tomorrow’s small-group discussion',
+ });
+ const label = discussion.lastElementChild;
+ if (!copy.firstElementChild || !label) throw new Error('Action button parts missing');
+ const lineHeight = Number.parseFloat(getComputedStyle(label).lineHeight);
+
+ await waitFor(async () => {
+ // The long label wraps to two clamped lines instead of widening the bar.
+ await expect(label.getBoundingClientRect().height).toBe(lineHeight * 2);
+ // Its box hugs its longest visible line, so the gaps beside it match the others.
+ const range = label.ownerDocument.createRange();
+ range.selectNodeContents(label);
+ const visibleLines = Array.from(range.getClientRects()).filter(
+ (line) => line.top < label.getBoundingClientRect().bottom,
+ );
+ const widest = Math.max(...visibleLines.map((line) => line.width));
+ await expect(label.getBoundingClientRect().width - widest).toBeLessThan(1);
+ });
+ // A taller button grows downward: icons stay level, and the swatches and divider
+ // stay centered on a one-line button.
+ for (const button of actions.getAllByRole('button').filter((b) => !b.closest('[role=group]'))) {
+ if (!button.firstElementChild) throw new Error('Action icon missing');
+ await expect(centerY(button.firstElementChild)).toBeCloseTo(
+ centerY(copy.firstElementChild),
+ 0,
+ );
+ }
+ await expect(centerY(actions.getByRole('group', { name: 'Highlight colors' }))).toBeCloseTo(
+ centerY(copy),
+ 0,
+ );
+ await expect(discussion).toHaveAttribute('title', discussion.getAttribute('aria-label'));
+ await expect(copy).not.toHaveAttribute('title');
+ },
+};
diff --git a/packages/ui/src/components/verse-action-popover.tsx b/packages/ui/src/components/verse-action-popover.tsx
index aa6497ebd..41d021812 100644
--- a/packages/ui/src/components/verse-action-popover.tsx
+++ b/packages/ui/src/components/verse-action-popover.tsx
@@ -201,20 +201,55 @@ function highlightSwatchLabel(t: TFunction, color: string, showRemove: boolean):
type ActionButtonProps = {
icon: ReactNode;
label: string;
+ /** Full text on hover, for host labels that may be clamped. */
+ title?: string;
onClick: () => void;
onClickCapture?: () => void;
};
-function ActionButton({ icon, label, onClick, onClickCapture }: ActionButtonProps) {
+function ActionButton({ icon, label, title, onClick, onClickCapture }: ActionButtonProps) {
+ // CSS sizes a wrapped label to the 8rem cap rather than to its longest line, which
+ // leaves wider gaps beside it than between one-line actions. Shrink the label to its
+ // longest line, in em so zoom and text size keep the fit.
+ const labelRef = useRef(null);
+ useLayoutEffect(() => {
+ const element = labelRef.current;
+ // Skip an element without layout, such as one rendered in jsdom.
+ if (!element?.offsetWidth) return;
+ const fit = (): void => {
+ element.style.inlineSize = '';
+ const range = element.ownerDocument.createRange();
+ range.selectNodeContents(element);
+ // Lines hidden by the two-line clamp still report rects; skip them. Rects include
+ // the bar's zoom-in transform, so divide it out.
+ const { bottom, width } = element.getBoundingClientRect();
+ 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`;
+ };
+ fit();
+ // A web font that finishes loading changes the line widths.
+ const { fonts } = element.ownerDocument;
+ fonts.addEventListener('loadingdone', fit);
+ return () => fonts.removeEventListener('loadingdone', fit);
+ }, [label]);
+
return (
);
}
@@ -572,7 +614,7 @@ export const VerseActionPopover: FC = ({
'yv:bg-card yv:text-popover-foreground',
'yv:rounded-full yv:drop-shadow-[0px_4.8432px_20px_rgba(0,0,0,0.19)]',
'yv:px-4 yv:py-2',
- 'yv:flex yv:items-center yv:gap-1',
+ 'yv:flex yv:items-start yv:gap-1',
// Never wider than the viewport (minus collision padding). When the
// swatch row can't fit, it scrolls inside instead of overflowing the
// screen. Radix sets `--radix-popover-content-available-width`, but
@@ -614,7 +656,7 @@ export const VerseActionPopover: FC = ({
inert={!portal.open}
className={
view.scrollAllActions
- ? 'yv:flex yv:min-w-0 yv:items-center yv:gap-1 yv:overflow-x-auto yv:p-1 yv:-m-1'
+ ? 'yv:flex yv:min-w-0 yv:items-start yv:gap-1 yv:overflow-x-auto yv:p-1 yv:-m-1'
: 'yv:contents'
}
>
@@ -652,6 +694,7 @@ export const VerseActionPopover: FC = ({
key={`custom:${item.id}`}
icon={item.icon}
label={item.label}
+ title={item.label}
onClick={item.onSelect}
onClickCapture={markOverlayAction}
/>
@@ -659,9 +702,12 @@ export const VerseActionPopover: FC = ({
}
if (!highlightsEnabled) return null;
+ // The row top-aligns, so the divider and swatches center on a
+ // one-line action button (3rem) and keep their place when a host
+ // label wraps.
const divider = (
);
@@ -673,15 +719,15 @@ export const VerseActionPopover: FC = ({
ref={view.scrollAllActions ? undefined : setSwatchRow}
// `min-w-0` lets this flex child actually shrink below its
// content size so `overflow-x-auto` engages instead of widening
- // the pill. `py-1 -my-1` gives the hover:scale-110 swatches
- // vertical breathing room inside the (now-clipping) scroll box
- // without shifting the row's resting position. Scrollbar hidden;
- // the edge fade signals there's more to scroll.
+ // the pill. `py-1` gives the hover:scale-110 swatches vertical
+ // breathing room inside the (now-clipping) scroll box, and `my-1`
+ // completes the 3rem band. Scrollbar hidden; the edge fade signals
+ // there's more to scroll.
className={cn(
'yv:flex yv:items-center yv:gap-2',
view.scrollAllActions
- ? 'yv:shrink-0'
- : 'yv:min-w-0 yv:overflow-x-auto yv:scrollbar-hide yv:py-1 yv:-my-1',
+ ? 'yv:my-2 yv:shrink-0'
+ : 'yv:min-w-0 yv:overflow-x-auto yv:scrollbar-hide yv:py-1 yv:my-1',
)}
style={view.scrollAllActions ? undefined : scrollFadeMask(scrollFade)}
role="group"