Make gallery selection keyboard and screen reader friendly

The card and list row stay links. While the gallery is selecting they
describe their state (Selected / Not selected), Space toggles them, and
aria-keyshortcuts names the Ctrl/Cmd+Enter gesture that starts selecting.

The checkbox drawn on each item is now decorative: RCheckbox gains a
decorative mode that renders the box without an input or label, so it
is no longer a hidden tab stop or interactive content inside a link.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-09-30 21:20:11 -04:00
parent 3aba36d18b
commit 0f5f4e09ad
25 changed files with 233 additions and 32 deletions

View File

@@ -435,6 +435,8 @@
"select-file": "Избери {path}",
"selected-of": "{selected} от {total} избрани",
"selection-count": "{n} игри",
"selection-state-off": "Не е избрано",
"selection-state-on": "Избрано",
"set-as-default": "Задай ROM-а като основен",
"set-as-default-version": "Задай като версия по подразбиране",
"set-status": "Задай статус",

View File

@@ -435,6 +435,8 @@
"select-file": "Vybrat {path}",
"selected-of": "{selected} z {total} vybráno",
"selection-count": "{n} her",
"selection-state-off": "Nevybráno",
"selection-state-on": "Vybráno",
"set-as-default": "Nastavit ROM jako výchozí",
"set-as-default-version": "Nastavit jako výchozí verzi",
"set-status": "Nastavit stav",

View File

@@ -435,6 +435,8 @@
"select-file": "{path} auswählen",
"selected-of": "{selected} von {total} ausgewählt",
"selection-count": "{n} Spiele",
"selection-state-off": "Nicht ausgewählt",
"selection-state-on": "Ausgewählt",
"set-as-default": "ROM als Standard setzen",
"set-as-default-version": "Als Standardversion festlegen",
"set-status": "Status festlegen",

View File

@@ -435,6 +435,8 @@
"select-file": "Select {path}",
"selected-of": "{selected} of {total} selected",
"selection-count": "{n} games",
"selection-state-off": "Not selected",
"selection-state-on": "Selected",
"set-as-default": "Set ROM as default",
"set-as-default-version": "Set as default version",
"set-status": "Set status",

View File

@@ -435,6 +435,8 @@
"select-file": "Select {path}",
"selected-of": "{selected} of {total} selected",
"selection-count": "{n} games",
"selection-state-off": "Not selected",
"selection-state-on": "Selected",
"set-as-default": "Set ROM as default",
"set-as-default-version": "Set as default version",
"set-status": "Set status",

View File

@@ -435,6 +435,8 @@
"select-file": "Seleccionar archivo",
"selected-of": "{selected} de {total} seleccionados",
"selection-count": "{n} juegos",
"selection-state-off": "No seleccionado",
"selection-state-on": "Seleccionado",
"set-as-default": "Establecer ROM por defecto",
"set-as-default-version": "Establecer como versión por defecto",
"set-status": "Estado",

View File

@@ -435,6 +435,8 @@
"select-file": "Sélectionner {path}",
"selected-of": "{selected} sur {total} sélectionné(s)",
"selection-count": "{n} jeux",
"selection-state-off": "Non sélectionné",
"selection-state-on": "Sélectionné",
"set-as-default": "Définir une ROM par défaut",
"set-as-default-version": "Définir comme version par défaut",
"set-status": "Définir le statut",

View File

@@ -435,6 +435,8 @@
"select-file": "{path} kiválasztása",
"selected-of": "{selected} / {total} kiválasztva",
"selection-count": "{n} játék",
"selection-state-off": "Nincs kijelölve",
"selection-state-on": "Kijelölve",
"set-as-default": "ROM beállítása alapértelmezettként",
"set-as-default-version": "Beállítás alapértelmezett verzióként",
"set-status": "Állapot beállítása",

View File

@@ -435,6 +435,8 @@
"select-file": "Seleziona {path}",
"selected-of": "{selected} di {total} selezionati",
"selection-count": "{n} giochi",
"selection-state-off": "Non selezionato",
"selection-state-on": "Selezionato",
"set-as-default": "Imposta ROM come predefinita",
"set-as-default-version": "Imposta come versione predefinita",
"set-status": "Imposta stato",

View File

@@ -435,6 +435,8 @@
"select-file": "{path}を選択",
"selected-of": "{total}件中{selected}件を選択中",
"selection-count": "{n}件のゲーム",
"selection-state-off": "未選択",
"selection-state-on": "選択済み",
"set-as-default": "ROMをデフォルトに設定",
"set-as-default-version": "デフォルトバージョンに設定",
"set-status": "ステータスを設定",

View File

@@ -435,6 +435,8 @@
"select-file": "{path} 선택",
"selected-of": "{total}개 중 {selected}개 선택됨",
"selection-count": "{n}개 게임",
"selection-state-off": "선택 안 됨",
"selection-state-on": "선택됨",
"set-as-default": "기본 롬으로 설정",
"set-as-default-version": "기본 버전으로 설정",
"set-status": "상태 설정",

View File

@@ -435,6 +435,8 @@
"select-file": "Wybierz {path}",
"selected-of": "{selected} z {total} wybranych",
"selection-count": "{n} gier",
"selection-state-off": "Nie zaznaczono",
"selection-state-on": "Zaznaczono",
"set-as-default": "Ustaw ROM jako domyślny",
"set-as-default-version": "Ustaw jako wersję domyślną",
"set-status": "Ustaw status",

View File

@@ -435,6 +435,8 @@
"select-file": "Selecionar {path}",
"selected-of": "{selected} de {total} selecionado(s)",
"selection-count": "{n} jogos",
"selection-state-off": "Não selecionado",
"selection-state-on": "Selecionado",
"set-as-default": "Definir ROM como padrão",
"set-as-default-version": "Definir como versão padrão",
"set-status": "Definir status",

View File

@@ -435,6 +435,8 @@
"select-file": "Selectează {path}",
"selected-of": "{selected} din {total} selectate",
"selection-count": "{n} jocuri",
"selection-state-off": "Neselectat",
"selection-state-on": "Selectat",
"set-as-default": "Setează ca ROM implicit",
"set-as-default-version": "Setează ca versiune implicită",
"set-status": "Setează starea",

View File

@@ -435,6 +435,8 @@
"select-file": "Выбрать {path}",
"selected-of": "{selected} из {total} выбрано",
"selection-count": "{n} игр",
"selection-state-off": "Не выбрано",
"selection-state-on": "Выбрано",
"set-as-default": "Установить ром по умолчанию",
"set-as-default-version": "Установить как версию по умолчанию",
"set-status": "Задать статус",

View File

@@ -435,6 +435,8 @@
"select-file": "{path} seç",
"selected-of": "{total} dosyadan {selected} seçildi",
"selection-count": "{n} oyun",
"selection-state-off": "Seçilmedi",
"selection-state-on": "Seçildi",
"set-as-default": "ROM'u varsayılan yap",
"set-as-default-version": "Varsayılan sürüm olarak ayarla",
"set-status": "Durum ayarla",

View File

@@ -435,6 +435,8 @@
"select-file": "选择 {path}",
"selected-of": "已选择 {selected} 个,共 {total} 个",
"selection-count": "{n} 个游戏",
"selection-state-off": "未选择",
"selection-state-on": "已选择",
"set-as-default": "将 ROM 设置为默认",
"set-as-default-version": "设为默认版本",
"set-status": "设置状态",

View File

@@ -435,6 +435,8 @@
"select-file": "選擇 {path}",
"selected-of": "已選擇 {selected} / {total}",
"selection-count": "{n} 個遊戲",
"selection-state-off": "未選取",
"selection-state-on": "已選取",
"set-as-default": "將 ROM 設為預設",
"set-as-default-version": "設為預設版本",
"set-status": "設定狀態",

View File

@@ -21,7 +21,7 @@ import {
RTooltip,
} from "@v2/lib";
import { formatPlaytime, formatReleaseDate, releaseYear } from "@v2/utils/time";
import { computed, ref } from "vue";
import { computed, ref, useId } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import storeCollections from "@/stores/collections";
@@ -127,13 +127,24 @@ const rom = computed<SimpleRom | null>(() => {
const romName = computed(() =>
rom.value ? (rom.value.name ?? rom.value.fs_name_no_ext) : "",
);
const checkLabel = computed(() =>
t("rom.select-asset", { name: romName.value }),
);
const isSelected = computed(() =>
!isStatic.value && rom.value ? selection.isSelected(rom.value.id) : false,
);
// While the gallery is selecting, Enter toggles the row instead of opening
// it, so the link describes its selection state.
const selectingRow = computed(
() => !isStatic.value && !!rom.value && selection.enabled,
);
const selectionStateId = useId();
// Space toggles a selecting row the way it toggles a native checkbox.
function onRowKeydown(e: KeyboardEvent) {
const item = rom.value;
if (e.key !== " " || !selectingRow.value || !item) return;
if (props.position === undefined) return;
e.preventDefault();
selection.toggle(item, props.position);
}
function onCheckboxClick(e: MouseEvent) {
e.preventDefault();
@@ -350,16 +361,30 @@ function onRowPointerDown(e: PointerEvent) {
:style="[smAndDown ? undefined : gridStyle, entranceStyle]"
:href="rom ? `/rom/${rom.id}` : undefined"
:aria-label="rom ? t('common.open-item', { name: romName }) : undefined"
:aria-describedby="selectingRow ? selectionStateId : undefined"
:aria-keyshortcuts="
rom && !isStatic ? 'Control+Enter Meta+Enter' : undefined
"
:data-rom-position="position"
:data-rom-id="rom?.id"
:data-focus-key="rom ? `rom-${rom.id}` : undefined"
@click="onRowClick"
@keydown="onRowKeydown"
@mouseenter="onRowHighlight"
@focus="onRowHighlight"
@pointerdown="onRowPointerDown"
@contextmenu="selectionInput.handleContextMenu"
@animationend.self="endEntrance"
>
<span
v-if="selectingRow"
:id="selectionStateId"
class="game-list-row__selection-state"
>
{{
isSelected ? t("rom.selection-state-on") : t("rom.selection-state-off")
}}
</span>
<template v-if="rom">
<!-- COMPACT (phones / tablets): two lines plus the chevron; the
columns move into the detail panel below. -->
@@ -370,13 +395,12 @@ function onRowPointerDown(e: PointerEvent) {
v-if="!isStatic"
class="game-list-row__check"
:model-value="isSelected"
:aria-label="checkLabel"
shape="circle"
size="sm"
color="primary"
bare
hide-details
tabindex="-1"
decorative
@click="onCheckboxClick"
/>
</div>
@@ -509,13 +533,12 @@ function onRowPointerDown(e: PointerEvent) {
v-if="!isStatic"
class="game-list-row__check"
:model-value="isSelected"
:aria-label="checkLabel"
shape="circle"
size="sm"
color="primary"
bare
hide-details
tabindex="-1"
decorative
@click="onCheckboxClick"
/>
</div>
@@ -763,6 +786,16 @@ function onRowPointerDown(e: PointerEvent) {
</template>
<style scoped>
/* Visually hidden, still read as the item's description. */
.game-list-row__selection-state {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
.game-list-row {
/* An inline <a> would shrink-wrap its content and swallow the bleed. */
display: block;

View File

@@ -2,6 +2,8 @@ import { mount } from "@vue/test-utils";
import { createPinia, setActivePinia } from "pinia";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { ref } from "vue";
import storeGalleryRoms from "@/v2/stores/galleryRoms";
import storeGallerySelection from "@/v2/stores/gallerySelection";
import GameListRow from "./GameListRow.vue";
import { rom } from "./listRowFixture";
@@ -101,3 +103,32 @@ describe("list row on phones and tablets", () => {
expect(fields).toContain("en");
});
});
describe("list row selection", () => {
beforeEach(() => {
setActivePinia(createPinia());
smAndDown.value = false;
vi.spyOn(storeGalleryRoms(), "getRomAt").mockReturnValue(rom());
});
it("is a plain link while nothing is selected", () => {
const row = mountRow({ rom: undefined, position: 0 }).find("a");
expect(row.attributes("aria-describedby")).toBeUndefined();
});
it("describes its selection state in selection mode, and Space toggles it", async () => {
const selection = storeGallerySelection();
selection.toggle({ ...rom(), id: 99 }, 5);
const wrapper = mountRow({ rom: undefined, position: 0 });
const row = wrapper.find("a");
const state = () =>
wrapper.find(`#${row.attributes("aria-describedby")}`).text();
expect(state()).toBe("rom.selection-state-off");
await row.trigger("keydown", { key: " " });
expect(state()).toBe("rom.selection-state-on");
});
});

View File

@@ -87,13 +87,31 @@ describe("GameCard selection", () => {
expect(selection.ids).toEqual([2, 1]);
});
it("keeps aria-pressed off the link and names its checkbox", async () => {
it("is a plain link with a decorative checkbox while nothing is selected", async () => {
const wrapper = await mountCard(1, makeRouter());
const card = wrapper.find(".r-gc");
expect(wrapper.find(".r-gc").attributes("aria-pressed")).toBeUndefined();
expect(wrapper.find(".r-gc__check input").attributes("aria-label")).toBe(
"rom.select-asset",
);
expect(card.attributes("role")).toBeUndefined();
expect(card.attributes("aria-pressed")).toBeUndefined();
expect(card.attributes("aria-describedby")).toBeUndefined();
expect(wrapper.find(".r-gc__check input").exists()).toBe(false);
});
it("describes its selection state in selection mode, and Space toggles it", async () => {
const selection = storeGallerySelection();
selection.toggle(rom(2), 1);
const wrapper = await mountCard(1, makeRouter());
const card = wrapper.find(".r-gc");
const state = () =>
wrapper.find(`#${card.attributes("aria-describedby")}`).text();
expect(state()).toBe("rom.selection-state-off");
await card.trigger("keydown", { key: " " });
expect(selection.ids).toEqual([2, 1]);
expect(state()).toBe("rom.selection-state-on");
});
it("consumes a modifier click on the checkbox", async () => {

View File

@@ -38,7 +38,7 @@
// * `#overlay` slot renders content on top of the cover for badges
// that aren't part of the default gallery overlay (e.g. metadata
// provider logos in the match-flow source picker).
import { computed, provide, ref } from "vue";
import { computed, provide, ref, useId } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import type { SimpleRom } from "@/stores/roms";
@@ -291,13 +291,16 @@ const showCheckbox = computed(
const checkboxAlwaysOn = computed(
() => props.selectable && !props.decorative && selectionStore.enabled,
);
// While the gallery is selecting, Enter toggles the card instead of opening
// it, so the link describes its selection state.
const describesSelection = computed(
() => checkboxAlwaysOn.value && !props.static,
);
const selectionStateId = useId();
function onCheckboxClick(e: MouseEvent) {
// The checkbox itself is a deliberate selection gesture. We bind
// RCheckbox in "controlled" mode (only `:model-value`: no v-model),
// so the native input change is purely visual; `preventDefault`
// here cancels the label → input click default so the input never
// toggles itself, and our store mutation drives the next render.
// The box is decorative and the store drives its state. Stop the click
// here so the enclosing link doesn't navigate.
e.preventDefault();
e.stopPropagation();
if (props.position == null) return;
@@ -340,12 +343,18 @@ function onCardPointerDown(e: PointerEvent) {
selectionInput.handlePointerDown(props.rom, props.position, e);
}
function onStaticKeydown(e: KeyboardEvent) {
// Enter / Space activate the card when it's rendered as a plain
// <article role="button"> instead of a router-link.
if (e.key === "Enter" || e.key === " ") {
function onCardKeydown(e: KeyboardEvent) {
if (props.decorative || (e.key !== "Enter" && e.key !== " ")) return;
// A static card is an <article role="button">, so Enter / Space activate it.
if (props.static) {
e.preventDefault();
emit("click", e as unknown as MouseEvent);
return;
}
// Space toggles a selecting card the way it toggles a native checkbox.
if (e.key === " " && checkboxAlwaysOn.value && props.position != null) {
e.preventDefault();
selectionStore.toggle(props.rom, props.position);
}
}
@@ -377,12 +386,18 @@ function onStaticKeydown(e: KeyboardEvent) {
:style="{ '--r-cover-ratio': coverAspectRatio }"
:aria-label="decorative ? undefined : title"
:aria-pressed="static && !decorative ? selected : undefined"
:aria-describedby="describesSelection ? selectionStateId : undefined"
:aria-keyshortcuts="
selectable && !static && !decorative
? 'Control+Enter Meta+Enter'
: undefined
"
:data-rom-id="rom.id"
:data-rom-position="selectable ? position : undefined"
:data-focus-key="!decorative && !static ? `rom-${rom.id}` : undefined"
@click.capture="onCardClickCapture"
@click="onCardClick"
@keydown="static && !decorative ? onStaticKeydown($event) : undefined"
@keydown="onCardKeydown"
@mouseenter="onCoverEnter"
@mouseleave="onCoverLeave"
@focus="onCoverFocus"
@@ -390,6 +405,15 @@ function onStaticKeydown(e: KeyboardEvent) {
@pointerdown="onCardPointerDown"
@contextmenu="selectionInput.handleContextMenu"
>
<span
v-if="describesSelection"
:id="selectionStateId"
class="r-gc__selection-state"
>
{{
isSelected ? t("rom.selection-state-on") : t("rom.selection-state-off")
}}
</span>
<GameCover
ref="coverRef"
class="r-gc__art"
@@ -414,13 +438,12 @@ function onStaticKeydown(e: KeyboardEvent) {
v-if="showCheckbox"
class="r-gc__check"
:model-value="isSelected"
:aria-label="t('rom.select-asset', { name: title })"
shape="circle"
size="md"
color="primary"
bare
hide-details
tabindex="-1"
decorative
@click="onCheckboxClick"
/>
@@ -523,6 +546,16 @@ function onStaticKeydown(e: KeyboardEvent) {
</template>
<style scoped>
/* Visually hidden, still read as the item's description. */
.r-gc__selection-state {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
.r-gc {
/* The long press selects the card; iOS would offer its link callout too. */
-webkit-touch-callout: none;
@@ -935,8 +968,7 @@ html:not([data-input="pad"]) .r-gc:hover .r-gc__check,
.r-gc:focus-visible .r-gc__check,
.r-gc--focused .r-gc__check,
.r-gc--checkbox-on .r-gc__check,
.r-gc--selected .r-gc__check,
.r-gc__check:has(:focus-visible) {
.r-gc--selected .r-gc__check {
opacity: 1;
pointer-events: auto;
}

View File

@@ -397,6 +397,34 @@ export const Bare: Story = {
},
};
export const Decorative: Story = {
render: () => ({
components: { RCheckbox },
setup: () => ({ checked: ref(true) }),
template: `
<button
type="button"
role="checkbox"
:aria-checked="checked"
aria-label="Chrono Trigger"
style="display:inline-flex;align-items:center;gap:8px;padding:8px 12px"
@click="checked = !checked"
>
<RCheckbox :model-value="checked" decorative bare hide-details shape="circle" />
Chrono Trigger
</button>
`,
}),
parameters: {
docs: {
description: {
story:
"Use `decorative` when an enclosing control owns the state, such as a selectable card: the box mirrors it with no input of its own.",
},
},
},
};
// ── Motion ──────────────────────────────────────────────────────────
export const Toggle: Story = {

View File

@@ -1,8 +1,10 @@
import { parse as parseSfc } from "@vue/compiler-sfc";
import { mount } from "@vue/test-utils";
import postcss from "postcss";
import type { Rule } from "postcss";
import { describe, expect, it } from "vitest";
import source from "./RCheckbox.vue?raw";
import { RCheckbox } from "./index";
// happy-dom has no layout, so the stylesheet is checked directly.
function declarationsFor(selector: string): Record<string, string> {
@@ -27,3 +29,16 @@ describe("RCheckbox native input", () => {
expect(declarationsFor(".r-checkbox").position).toBe("relative");
});
});
describe("RCheckbox decorative", () => {
it("draws the box without an input or label", () => {
const wrapper = mount(RCheckbox, {
props: { modelValue: true, decorative: true },
});
expect(wrapper.find("input").exists()).toBe(false);
expect(wrapper.find("label").exists()).toBe(false);
expect(wrapper.find(".r-checkbox").attributes("aria-hidden")).toBe("true");
expect(wrapper.classes()).toContain("r-checkbox--checked");
});
});

View File

@@ -64,6 +64,9 @@ interface Props {
/** Error tone: red box + red label. */
error?: boolean;
errorMessages?: string | string[];
/** Draw the box only, with no input, for a mirror of state that an
* enclosing control already exposes. Hidden from assistive tech. */
decorative?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
@@ -83,6 +86,7 @@ const props = withDefaults(defineProps<Props>(), {
bare: false,
error: false,
errorMessages: () => [],
decorative: false,
});
const emit = defineEmits<{
@@ -204,11 +208,15 @@ const hasLabel = computed(
'--r-cb-fill': fillColor,
}"
>
<!-- eslint-disable-next-line vuejs-accessibility/label-has-for -- the native checkbox input is nested inside this label, a valid control association -->
<label class="r-checkbox">
<component
:is="decorative ? 'span' : 'label'"
class="r-checkbox"
:aria-hidden="decorative || undefined"
>
<!-- Native input: visually hidden but kept in the layout for
form submission, keyboard, and screen reader support. -->
<input
v-if="!decorative"
ref="inputRef"
type="checkbox"
class="r-checkbox__input"
@@ -267,7 +275,7 @@ const hasLabel = computed(
<slot name="subtitle">{{ subtitle }}</slot>
</span>
</span>
</label>
</component>
<div v-if="showDetailsRow" class="r-checkbox__details">
<span v-for="(m, i) in messages" :key="i" class="r-checkbox__message">