fix(frontend-v2): pin the recommendation caption to its cover's width

Capping the caption at `--r-card-art-w` read the global 158px, but
GameCard sets that token on itself, so the mobile override to 130px never
reached the sibling caption: a long one widened the wrapper past the
cover and threw the centring off. Pinning it the way GameCard pins its
own label tracks whatever width the card resolves to, size variants
included, and keeps the caption out of the row's scroll track.

Also strengthens the Home caption test, which passed on the key alone and
so missed a dropped interpolation value.

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 03:02:16 +00:00
committed by Claude
parent bb421217bd
commit 74b1152774
3 changed files with 20 additions and 15 deletions

View File

@@ -49,15 +49,16 @@ const caption = computed(() => {
<style scoped>
.rec-reason {
display: inline-flex;
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
/* 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;
/* Pinned to the cover's width without widening the row's scroll track, the
way GameCard pins its own label. Reading the card-width token instead
would miss the sizes GameCard overrides on itself, mobile's among them. */
width: 0;
min-width: 100%;
max-width: 100%;
overflow: hidden;
font-size: 10.5px;
font-weight: var(--r-font-weight-medium);
@@ -74,9 +75,8 @@ const caption = computed(() => {
}
.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. */
/* MDI glyphs centre on the em box, leaving them ~2px below the text's
optical centre. A transform, because centring absorbs half of a margin. */
transform: translateY(-1px);
}
</style>

View File

@@ -30,8 +30,8 @@ const FACET_ICONS: Record<Facet, string> = {
const TRANSLATED_FACETS: Partial<Record<Facet, string>> = {
igdb: "recommendations.reason-igdb",
top_rated: "recommendations.reason-top-rated",
// Decades arrive as the starting year ("1990"); each locale suffixes it
// its own way, so the phrasing belongs in the locale files.
// Decades arrive as the starting year ("1990"), which each locale phrases
// in its own way, so the wording belongs in the locale files.
decade: "recommendations.reason-decade",
};

View File

@@ -10,7 +10,12 @@ import { useStreamingStore, type JoinableSession } from "@/stores/streaming";
import Home from "./Home.vue";
vi.mock("vue-i18n", () => ({
useI18n: () => ({ t: (key: string) => key }),
useI18n: () => ({
// Renders interpolated values alongside the key, so a caption that drops
// its parameter fails here instead of passing on the bare key.
t: (key: string, params?: unknown[]) =>
[key, ...(params ?? [])].filter(Boolean).join(":"),
}),
}));
const { getLibraryInfo, getRecommendedRoms } = vi.hoisted(() => ({
@@ -245,8 +250,8 @@ describe("Home", () => {
expect(getRecommendedRoms).toHaveBeenCalledTimes(1);
const caption = wrapper.find(".rec-reason");
expect(caption.text()).toBe("Super Metroid");
expect(caption.attributes("title")).toContain(
"recommendations.because-you-played",
expect(caption.attributes("title")).toBe(
"recommendations.because-you-played:Super Metroid",
);
});