fix(frontend-v2): show the gallery scrollbar and add a back-to-top button

The gallery scroller hid its scrollbar with r-v2-scroll-hidden, leaving no
scroll position cue on long libraries. It now shows the themed scrollbar with
a stable gutter; the row packer, AlphaStrip, floating dock and top bar all
clear its width. A floating back-to-top button appears once the viewer is a
viewport down, honors reduced motion, and hands keyboard/pad focus to the
first control at the top.

Fixes #4365

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-09-28 14:44:18 -04:00
parent 9798afdc7a
commit ad5e4b8097
22 changed files with 242 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Всички игри са заредени",
"back-to-top": "Към началото",
"filters": "Филтри",
"firmware-files-count": "{count} файла",
"firmware-selected-count": "{count} избрани",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Všechny hry byly načteny",
"back-to-top": "Zpět nahoru",
"filters": "Filtry",
"firmware-files-count": "{count} souborů",
"firmware-selected-count": "{count} vybráno",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Alle Spiele wurden geladen",
"back-to-top": "Nach oben",
"filters": "Filter",
"firmware-files-count": "{count} Dateien",
"firmware-selected-count": "{count} ausgewählt",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "All games have been loaded",
"back-to-top": "Back to top",
"filters": "Filters",
"firmware-files-count": "{count} files",
"firmware-selected-count": "{count} selected",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "All games have been loaded",
"back-to-top": "Back to top",
"filters": "Filters",
"firmware-files-count": "{count} files",
"firmware-selected-count": "{count} selected",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Todos los juegos han sido cargados",
"back-to-top": "Volver arriba",
"filters": "Filtros",
"firmware-files-count": "{count} archivos",
"firmware-selected-count": "{count} seleccionados",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Tous les jeux ont été chargés",
"back-to-top": "Retour en haut",
"filters": "Filtres",
"firmware-files-count": "{count} fichiers",
"firmware-selected-count": "{count} sélectionné(s)",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Minden játék betöltődött",
"back-to-top": "Vissza a tetejére",
"filters": "Szűrők",
"firmware-files-count": "{count} fájl",
"firmware-selected-count": "{count} kiválasztva",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Tutti i giochi sono stati caricati",
"back-to-top": "Torna su",
"filters": "Filtri",
"firmware-files-count": "{count} file",
"firmware-selected-count": "{count} selezionati",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "すべてのゲームが読み込まれました",
"back-to-top": "トップへ戻る",
"filters": "フィルタ",
"firmware-files-count": "{count}件のファイル",
"firmware-selected-count": "{count}件選択中",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "모든 게임이 불러와졌습니다",
"back-to-top": "맨 위로",
"filters": "필터",
"firmware-files-count": "{count}개 파일",
"firmware-selected-count": "{count}개 선택됨",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Wszystkie gry zostały załadowane",
"back-to-top": "Powrót na górę",
"filters": "Filtry",
"firmware-files-count": "{count} plików",
"firmware-selected-count": "{count} wybrano",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Todos os jogos foram carregados",
"back-to-top": "Voltar ao topo",
"filters": "Filtros",
"firmware-files-count": "{count} arquivos",
"firmware-selected-count": "{count} selecionado(s)",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Toate jocurile au fost încărcate",
"back-to-top": "Înapoi sus",
"filters": "Filtre",
"firmware-files-count": "{count} fișiere",
"firmware-selected-count": "{count} selectate",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Все игры загружены",
"back-to-top": "Наверх",
"filters": "Фильтры",
"firmware-files-count": "{count} файлов",
"firmware-selected-count": "{count} выбрано",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "Tüm oyunlar yüklendi",
"back-to-top": "Başa dön",
"filters": "Filtreler",
"firmware-files-count": "{count} dosya",
"firmware-selected-count": "{count} seçildi",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "所有游戏已加载",
"back-to-top": "返回顶部",
"filters": "筛选器",
"firmware-files-count": "{count} 个文件",
"firmware-selected-count": "已选择 {count} 个",

View File

@@ -1,5 +1,6 @@
{
"all-loaded": "所有遊戲已載入",
"back-to-top": "回到頂端",
"filters": "篩選器",
"firmware-files-count": "{count} 個檔案",
"firmware-selected-count": "已選擇 {count} 個",

View File

@@ -111,7 +111,8 @@ onBeforeUnmount(() => {
position: fixed;
top: 0;
left: 0;
right: 0;
/* Clears a gallery scroller's scrollbar, which runs up under the bar. */
right: var(--r-v2-shell-scrollbar-w, 0px);
z-index: 100;
height: var(--r-nav-h);
background: transparent;

View File

@@ -0,0 +1,89 @@
import { mount } from "@vue/test-utils";
import { afterEach, describe, expect, it, vi } from "vitest";
import BackToTopButton from "./BackToTopButton.vue";
vi.mock("vue-i18n", () => ({
useI18n: () => ({ t: (key: string) => key }),
}));
const reducedMotion = { value: false };
vi.mock("@/v2/composables/useReducedMotion", () => ({
useReducedMotion: () => ({ enabled: reducedMotion }),
}));
function makeScroller(clientHeight = 800) {
const el = document.createElement("div");
Object.defineProperty(el, "clientHeight", { value: clientHeight });
el.scrollTo = vi.fn() as typeof el.scrollTo;
const first = document.createElement("button");
first.className = "first";
el.appendChild(first);
document.body.appendChild(el);
return el;
}
function mountButton(scroller: HTMLElement, scrollTop: number) {
return mount(BackToTopButton, {
attachTo: document.body,
props: { scroller, scrollTop },
global: { stubs: { transition: false } },
});
}
afterEach(() => {
document.body.innerHTML = "";
reducedMotion.value = false;
});
describe("BackToTopButton", () => {
it("stays hidden within the first viewport", () => {
const wrapper = mountButton(makeScroller(), 400);
expect(wrapper.find("button").exists()).toBe(false);
});
it("shows once scrolled past a viewport", async () => {
const wrapper = mountButton(makeScroller(), 400);
await wrapper.setProps({ scrollTop: 1200 });
expect(wrapper.get("button").attributes("aria-label")).toBe(
"gallery.back-to-top",
);
});
it("smooth-scrolls the scroller to the top and emits", async () => {
const scroller = makeScroller();
const wrapper = mountButton(scroller, 1200);
await wrapper.get("button").trigger("click");
expect(scroller.scrollTo).toHaveBeenCalledWith({
top: 0,
behavior: "smooth",
});
expect(wrapper.emitted("scroll-to-top")).toHaveLength(1);
});
it("jumps without animation under reduced motion", async () => {
reducedMotion.value = true;
const scroller = makeScroller();
const wrapper = mountButton(scroller, 1200);
await wrapper.get("button").trigger("click");
expect(scroller.scrollTo).toHaveBeenCalledWith({
top: 0,
behavior: "auto",
});
});
it("hands keyboard focus to the first control at the top", async () => {
const scroller = makeScroller();
const wrapper = mountButton(scroller, 1200);
const btn = wrapper.get("button");
(btn.element as HTMLElement).focus();
await btn.trigger("click");
expect(document.activeElement).toBe(scroller.querySelector(".first"));
});
it("leaves focus alone on a pointer click", async () => {
const scroller = makeScroller();
const wrapper = mountButton(scroller, 1200);
await wrapper.get("button").trigger("click");
expect(document.activeElement).not.toBe(scroller.querySelector(".first"));
});
});

View File

@@ -0,0 +1,82 @@
<script setup lang="ts">
// BackToTopButton: floating control that returns a long gallery scroll to
// its top, shown once the viewer is more than a viewport down.
import { RBtn } from "@v2/lib";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useReducedMotion } from "@/v2/composables/useReducedMotion";
import { FOCUSABLE_SELECTOR } from "@/v2/utils/spatialNav";
interface Props {
scroller: HTMLElement | null;
scrollTop: number;
}
const props = defineProps<Props>();
const emit = defineEmits<{
(e: "scroll-to-top"): void;
}>();
const { t } = useI18n();
const { enabled: reducedMotion } = useReducedMotion();
const visible = computed(
() => !!props.scroller && props.scrollTop > props.scroller.clientHeight,
);
function scrollToTop(event: MouseEvent) {
const el = props.scroller;
if (!el) return;
emit("scroll-to-top");
const hadFocus =
event.currentTarget instanceof HTMLElement &&
event.currentTarget.contains(document.activeElement);
el.scrollTo({ top: 0, behavior: reducedMotion.value ? "auto" : "smooth" });
// The button unmounts at the top, so keyboard and pad focus lands on the
// first control up there instead of falling back to the body.
if (hadFocus) {
el.querySelector<HTMLElement>(FOCUSABLE_SELECTOR)?.focus({
preventScroll: true,
});
}
}
</script>
<template>
<Transition name="back-to-top">
<RBtn
v-if="visible"
class="back-to-top"
variant="elevated"
surface
border
rounded="circle"
icon="mdi-chevron-up"
:aria-label="t('gallery.back-to-top')"
:tooltip="t('gallery.back-to-top')"
tooltip-location="start"
@click="scrollToTop"
/>
</Transition>
</template>
<style scoped>
.back-to-top-enter-active,
.back-to-top-leave-active {
transition:
opacity var(--r-motion-med) var(--r-motion-ease-out),
transform var(--r-motion-med) var(--r-motion-ease-out);
}
.back-to-top-enter-from,
.back-to-top-leave-to {
opacity: 0;
transform: translateY(8px);
}
@media (prefers-reduced-motion: reduce) {
.back-to-top-enter-active,
.back-to-top-leave-active {
transition: none;
}
}
</style>

View File

@@ -25,7 +25,7 @@ import {
RLetterHeading,
RVirtualScroller,
} from "@v2/lib";
import { useIntersectionObserver } from "@vueuse/core";
import { useIntersectionObserver, useResizeObserver } from "@vueuse/core";
import { storeToRefs } from "pinia";
import {
computed,
@@ -42,6 +42,7 @@ import { useUISettings } from "@/composables/useUISettings";
import storeGalleryFilter from "@/stores/galleryFilter";
import AlphaJumpMenu from "@/v2/components/Gallery/AlphaJumpMenu.vue";
import AlphaStrip from "@/v2/components/Gallery/AlphaStrip.vue";
import BackToTopButton from "@/v2/components/Gallery/BackToTopButton.vue";
import FilterDrawer from "@/v2/components/Gallery/FilterDrawer.vue";
import GalleryToolbar from "@/v2/components/Gallery/GalleryToolbar.vue";
import GameListHeader from "@/v2/components/Gallery/GameListHeader.vue";
@@ -318,6 +319,9 @@ const jumpMenuVisible = computed(
// The strip's footprint: its letter column plus `--r-alpha-strip-gap`.
const STRIP_INSET_PX =
parseInt(layoutTokens.alphaStripWidth, 10) + parseInt(space[3], 10);
// The scroller's classic scrollbar gutter (0 for overlay scrollbars), which
// the rows and the strip both have to clear.
const scrollbarWidth = ref(0);
// Card-art width reference (matches GameCard's `--r-card-art-w`); sets the
// fixed card HEIGHT (a 2/3 cover at this width). Real width follows the ratio.
const CARD_GAP_PX = 12;
@@ -328,7 +332,8 @@ const { columns, usableWidth } = useResponsiveColumns(sectionEl, {
gap: CARD_GAP_PX,
inset: () =>
(xs.value ? 28 : smAndDown.value ? 40 : 72) +
(stripVisible.value ? STRIP_INSET_PX : 0),
(stripVisible.value ? STRIP_INSET_PX : 0) +
scrollbarWidth.value,
});
// Fallback cover ratio (boxart style) — the per-card `--r-cover-ratio` seed
@@ -427,6 +432,20 @@ const { virtualItems, letterToIndex, availableLetters, getItemHeight } =
});
const scrollerRef = ref<InstanceType<typeof RVirtualScroller> | null>(null);
const scrollerEl = computed(() => scrollerRef.value?.containerEl ?? null);
useResizeObserver(scrollerEl, () => {
const el = scrollerEl.value;
if (el) scrollbarWidth.value = el.offsetWidth - el.clientWidth;
});
// Published on <html> so the fixed top bar can stop short of the scrollbar,
// which it would otherwise cover.
const SCROLLBAR_W_VAR = "--r-v2-shell-scrollbar-w";
watch(scrollbarWidth, (w) => {
document.documentElement.style.setProperty(SCROLLBAR_W_VAR, `${w}px`);
});
onBeforeUnmount(() => {
document.documentElement.style.removeProperty(SCROLLBAR_W_VAR);
});
// Where the open row sits in the packed list. Recomputed when a row opens or
// the list re-packs, never on the animation's frames.
@@ -940,7 +959,7 @@ defineExpose({
:min-content-width="
layout === 'list' && !smAndDown ? listMinWidth : undefined
"
class="r-v2-shell__scroller r-v2-scroll-hidden"
class="r-v2-shell__scroller"
:tabindex="-1"
@wheel.passive="endLetterJump"
@pointerdown.passive="endLetterJump"
@@ -1115,6 +1134,14 @@ defineExpose({
@pick="scrollToLetter"
/>
<BackToTopButton
v-if="!(smAndDown && gallerySelection.enabled)"
class="r-v2-shell__back-to-top"
:scroller="scrollerEl"
:scroll-top="scrollTopNow"
@scroll-to-top="endLetterJump"
/>
<!-- FLOATING-DOCK TOOLBAR — the alternative dock; sits permanently
in the top-right and never scrolls. Mutually exclusive with
the in-scroller header dock above. -->
@@ -1240,6 +1267,9 @@ html[data-bp~="md-and-up"] .r-v2-shell__list-header {
flex: 1;
height: 100%;
scroll-timeline: --r-v2-shell-scroll block;
/* A stable gutter keeps the row packing from shifting when the content
starts or stops overflowing. */
scrollbar-gutter: stable;
padding: 0 calc(var(--r-row-pad) + var(--r-v2-shell-strip)) 60px
var(--r-row-pad);
}
@@ -1326,7 +1356,7 @@ html[data-bp~="md-and-up"] .r-v2-shell__list-header {
.r-v2-shell .r-v2-shell__strip {
position: absolute;
top: calc(var(--r-nav-h) + var(--r-v2-shell-toolbar-h));
right: 0;
right: var(--r-v2-shell-scrollbar-w, 0px);
bottom: 0;
z-index: 5;
justify-content: flex-start;
@@ -1377,9 +1407,26 @@ html[data-bp~="md-and-up"] .r-v2-shell__list-header {
}
}
/* Bottom corner of the rows' column, clear of the strip and the scrollbar. */
.r-v2-shell__back-to-top {
position: absolute;
right: calc(
var(--r-row-pad) + var(--r-v2-shell-strip) +
var(--r-v2-shell-scrollbar-w, 0px)
);
bottom: var(--r-space-6);
z-index: 6;
}
html[data-bp~="sm-and-down"] .r-v2-shell__back-to-top {
bottom: calc(
var(--r-bottom-nav-h) + env(safe-area-inset-bottom) + var(--r-space-4)
);
}
/* The section runs under the top bar; keep the floating dock below it. */
.r-v2-shell .r-v2-shell__floating {
top: calc(var(--r-nav-h) + 14px);
margin-right: var(--r-v2-shell-scrollbar-w, 0px);
}
/* Smaller cards on phones. Matches GameCard's own xs `--r-card-art-w` so