fix(frontend-v2): centre the recommendation caption under the card

The caption under a recommended game card was left-aligned while the card
title above it was centred. Centre the caption instead of left-aligning
the title, so the change stays inside the recommendation feed rather than
shifting every GameCard in the gallery, the similar-games grids and the
match-ROM picker.

Two things stood in the way of centring:

- "Because you played X" never fit the cover width, so it filled the
  caption and could not centre. It now captions the seed game on its own,
  with a play icon, the way every facet reason is captioned; the full
  sentence moves to the title tooltip, so no locale keys change.
- The ellipsis sat on the flex container, where it does nothing: an
  anonymous text run has no box to truncate, so an over-long caption was
  cut mid-word. It now lives on a real child span.

Also nudge the reason icon onto the caption's optical centre. MDI glyphs
centre on the em box, leaving them ~2px low against the text's cap height.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01427KQPf6WHJQ8feMKYp24Z
This commit is contained in:
Sam Dornan
2026-09-15 02:31:40 +00:00
committed by Claude
parent 0f4db4dfc2
commit d3833ca817
3 changed files with 50 additions and 22 deletions

View File

@@ -7,31 +7,44 @@ import { useI18n } from "vue-i18n";
import type { SimilarityReasonSchema } from "@/__generated__";
import { reasonIcon, reasonLabel } from "@/v2/utils/similarityReasons";
const SEED_ICON = "mdi-play";
const props = defineProps<{
reasons: SimilarityReasonSchema[];
// Takes the place of the facet chip where the feed knows the seed game,
// e.g. "Because you played Super Metroid".
label?: string | null;
// Captions the card with the game the recommendation came from, in place
// of the first facet.
seedRomName?: string | null;
}>();
const { t } = useI18n();
const reason = computed(() =>
props.label ? null : (props.reasons[0] ?? null),
props.seedRomName ? null : (props.reasons[0] ?? null),
);
const icon = computed(() => {
if (props.seedRomName) return SEED_ICON;
return reason.value ? reasonIcon(reason.value) : null;
});
const text = computed(() => {
if (props.seedRomName) return props.seedRomName;
return reason.value ? reasonLabel(reason.value, t) : null;
});
// The seed name alone fits the card where the full sentence never did, so
// the sentence lives here.
const title = computed(() =>
props.seedRomName
? t("recommendations.because-you-played", [props.seedRomName])
: t("recommendations.why"),
);
</script>
<template>
<span
v-if="label || reason"
class="rec-reason"
:title="t('recommendations.why')"
>
<template v-if="label">{{ label }}</template>
<template v-else-if="reason">
<RIcon :icon="reasonIcon(reason)" size="11" />
{{ reasonLabel(reason, t) }}
</template>
<span v-if="text" class="rec-reason" :title="title">
<RIcon v-if="icon" class="rec-reason__icon" :icon="icon" size="11" />
<span class="rec-reason__text">{{ text }}</span>
</span>
</template>
@@ -43,11 +56,28 @@ const reason = computed(() =>
/* Clip to the card it captions rather than widening the row's scroll
track; the token tracks the per-breakpoint card width. */
max-width: var(--r-card-art-w);
/* Centres the caption under the card's centred title. Auto margins, not
`justify-content`, so an over-long caption still truncates from one end. */
margin-inline: auto;
overflow: hidden;
font-size: 10.5px;
font-weight: var(--r-font-weight-medium);
color: var(--r-color-fg-faint);
white-space: nowrap;
}
/* The caption is a flex container, so the ellipsis has to live on a real
child: an anonymous text run never truncates, it just gets cut off. */
.rec-reason__text {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
.rec-reason__icon {
/* MDI glyphs centre on the em box, which the text's descender space drops
~2px below its optical centre. Transform, not margin: centring absorbs
half of a margin, and a whole pixel stays crisp at 1x. */
transform: translateY(-1px);
}
</style>

View File

@@ -243,7 +243,11 @@ describe("Home", () => {
await flushPromises();
expect(getRecommendedRoms).toHaveBeenCalledTimes(1);
expect(wrapper.text()).toContain("recommendations.because-you-played");
const caption = wrapper.find(".rec-reason");
expect(caption.text()).toBe("Super Metroid");
expect(caption.attributes("title")).toContain(
"recommendations.because-you-played",
);
});
it("hides the recommendations row when the feed comes back empty", async () => {

View File

@@ -436,13 +436,7 @@ function collectionCovers(c: {
/>
<RecommendationReason
:reasons="item.reasons"
:label="
item.seed_rom_name
? t('recommendations.because-you-played', [
item.seed_rom_name,
])
: null
"
:seed-rom-name="item.seed_rom_name"
/>
</div>
</template>