fix(a11y): the games table is a table, the cards a list
The games table: - The rows were <a role="row"> with nothing around them, so a screen reader read them as neither a link nor a table. The grid now has the complete ARIA table: role="table" with aria-rowcount/aria-colcount, a rowgroup, and aria-rowindex on every virtualised row. The icon-only columns have names for screen readers (srLabel), and the non-sortable "Platforms" header is plain text rather than a disabled button. - A row is no longer a link wrapped around a fake one. The name is the row's only Tab stop, and its link stretches over the row, so a click anywhere still opens the game. The Steam icon is a real link, kept out of the Tab order (a game's page has the same links). The tooltips sit above the stretched link, and screen readers get their words. - The row draws the focus ring, because the cells clip overflow. The phone cards are a list with aria-setsize/aria-posinset. Both panes keep a minimum height (min-h-64). Sized to the window alone, they shrank to nothing at 300-400% zoom. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0f68351fb8
commit
e827ac83a7
5 files changed
+153
-113
No files matched your search
@@ -170,6 +170,10 @@
|
||||
"filterAllStatus": "All status",
|
||||
"hideDead": "Hide dead",
|
||||
"colName": "Name",
|
||||
"colImage": "Image",
|
||||
"colIssues": "Data issues",
|
||||
"colSteam": "Steam page",
|
||||
"openOnSteamNamed": "Open {{name}} on Steam",
|
||||
"noResults": "No game matches these filters.",
|
||||
"clearFilters": "Clear filters",
|
||||
"showing": "{{shown}} of {{total}}",
|
||||
|
||||
@@ -170,6 +170,10 @@
|
||||
"filterAllStatus": "Mọi trạng thái",
|
||||
"hideDead": "Ẩn dead",
|
||||
"colName": "Tên",
|
||||
"colImage": "Ảnh",
|
||||
"colIssues": "Vấn đề dữ liệu",
|
||||
"colSteam": "Trang Steam",
|
||||
"openOnSteamNamed": "Mở {{name}} trên Steam",
|
||||
"noResults": "Không có game nào khớp bộ lọc này.",
|
||||
"clearFilters": "Xóa bộ lọc",
|
||||
"showing": "{{shown}} trên {{total}}",
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
import { imgFallback } from "../img-fallback";
|
||||
import { recordIssues } from "../validation";
|
||||
import { formatNumber, parseReviewPercent, cn } from "../utils";
|
||||
import { openExternal } from "../external-open";
|
||||
import Badge from "../ui/Badge.svelte";
|
||||
import AntiCheatBadge from "./AntiCheatBadge.svelte";
|
||||
|
||||
let { rows }: { rows: GameRecord[] } = $props();
|
||||
|
||||
@@ -63,62 +63,87 @@
|
||||
</script>
|
||||
|
||||
<div class="overflow-hidden rounded-lg border bg-card">
|
||||
<div bind:this={viewport} class="h-[calc(100dvh-20rem)] overflow-auto scrollbar-slim scrollbar-panel">
|
||||
<div style:width="{TOTAL_WIDTH}px" style:min-width="100%">
|
||||
<!-- Sticky header. A real <table> cannot be virtualised without either
|
||||
losing sticky headers or fighting the row heights, so this is a grid
|
||||
that keeps the table SEMANTICS through role attributes. -->
|
||||
<!-- min-h: the height follows the window, so at 300-400% zoom it reached
|
||||
zero and the list vanished. Taller than a tiny window, the page scrolls. -->
|
||||
<div bind:this={viewport} class="h-[calc(100dvh-20rem)] min-h-64 overflow-auto scrollbar-slim scrollbar-panel">
|
||||
<!-- A real <table> cannot be virtualised without either losing the sticky
|
||||
header or fighting the row heights, so this is a grid of divs with the
|
||||
ARIA table roles. They have to be complete to mean anything: the table
|
||||
around the rows, the row and column counts (only the rows on screen
|
||||
exist), and a row index on each. Rows used to be <a role="row"> with no
|
||||
table around them, which a screen reader announced as neither a link
|
||||
nor a table. -->
|
||||
<div
|
||||
role="table"
|
||||
aria-label={t("games.title")}
|
||||
aria-rowcount={rows.length + 1}
|
||||
aria-colcount={COLS.length}
|
||||
style:width="{TOTAL_WIDTH}px"
|
||||
style:min-width="100%"
|
||||
>
|
||||
<div
|
||||
role="row"
|
||||
aria-rowindex={1}
|
||||
class="sticky top-0 z-10 flex h-10 items-center border-b bg-card/95 backdrop-blur"
|
||||
>
|
||||
{#each COLS as col (col.key)}
|
||||
{@const active = filters.sortKey === col.key}
|
||||
<div
|
||||
role="columnheader"
|
||||
aria-sort={active ? (filters.sortDir === "asc" ? "ascending" : "descending") : "none"}
|
||||
aria-sort={col.sortable ? (active ? (filters.sortDir === "asc" ? "ascending" : "descending") : "none") : undefined}
|
||||
style:width="{col.width}px"
|
||||
class="shrink-0 px-2"
|
||||
>
|
||||
{#if col.label}
|
||||
{#if col.label && col.sortable}
|
||||
<button
|
||||
type="button"
|
||||
disabled={!col.sortable}
|
||||
onclick={() => toggleSort(col.key, col.sortable)}
|
||||
title={col.sortable ? t("games.sortBy", { column: t(col.label) }) : undefined}
|
||||
title={t("games.sortBy", { column: t(col.label) })}
|
||||
class={cn(
|
||||
"flex w-full items-center gap-1 text-xs font-semibold uppercase tracking-wide",
|
||||
"flex w-full items-center gap-1 text-xs font-semibold uppercase tracking-wide hover:text-foreground",
|
||||
col.align === "right" && "justify-end",
|
||||
col.sortable ? "hover:text-foreground" : "cursor-default",
|
||||
active ? "text-foreground" : "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
<span class="truncate">{t(col.label)}</span>
|
||||
{#if col.sortable}
|
||||
{#if !active}
|
||||
<ChevronsUpDown class="size-3 shrink-0 opacity-40" />
|
||||
{:else if filters.sortDir === "asc"}
|
||||
<ChevronUp class="size-3 shrink-0" />
|
||||
{:else}
|
||||
<ChevronDown class="size-3 shrink-0" />
|
||||
{/if}
|
||||
{#if !active}
|
||||
<ChevronsUpDown class="size-3 shrink-0 opacity-40" />
|
||||
{:else if filters.sortDir === "asc"}
|
||||
<ChevronUp class="size-3 shrink-0" />
|
||||
{:else}
|
||||
<ChevronDown class="size-3 shrink-0" />
|
||||
{/if}
|
||||
</button>
|
||||
{:else if col.label}
|
||||
<!-- Not sortable: plain text, not a disabled button that a screen
|
||||
reader announces as one. -->
|
||||
<span class="block truncate text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
||||
{t(col.label)}
|
||||
</span>
|
||||
{:else if col.srLabel}
|
||||
<span class="sr-only">{t(col.srLabel)}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div style:height="{$virtualizer.getTotalSize()}px" class="relative">
|
||||
<div role="rowgroup" style:height="{$virtualizer.getTotalSize()}px" class="relative">
|
||||
{#each items as item (item.key)}
|
||||
{@const g = rows[item.index]}
|
||||
{@const appid = appidOf(g)}
|
||||
{@const issues = recordIssues(g)}
|
||||
{@const pct = parseReviewPercent(g.reviews)}
|
||||
<a
|
||||
href={appid ? `/games/${appid}` : g.link}
|
||||
<!-- The whole row still opens the game: the name's link stretches
|
||||
over it (after:absolute inset-0, against this positioned row), so
|
||||
there is one link per row instead of a row that is a link.
|
||||
Things that must stay hoverable or clickable on their own (the
|
||||
warning and dead-game tooltips, the Steam link) sit above it
|
||||
with relative z-[1]. Its focus ring is drawn by the row: the
|
||||
cells clip overflow and would cut an outline off. -->
|
||||
<div
|
||||
role="row"
|
||||
class="absolute left-0 flex items-center border-b text-sm transition-colors hover:bg-accent/60"
|
||||
aria-rowindex={item.index + 2}
|
||||
class="absolute left-0 flex items-center border-b text-sm transition-colors hover:bg-accent/60 has-[:focus-visible]:bg-accent/60 has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring has-[:focus-visible]:ring-inset"
|
||||
style:height="{item.size}px"
|
||||
style:width="{TOTAL_WIDTH}px"
|
||||
style:transform="translateY({item.start}px)"
|
||||
@@ -150,18 +175,20 @@
|
||||
{/if}
|
||||
{:else if col.key === "issues"}
|
||||
{#if issues.length}
|
||||
<span
|
||||
class="grid size-5 place-items-center text-warning"
|
||||
title={issues.map((i) => t(i.message, i.vars)).join(" · ")}
|
||||
>
|
||||
{@const issueText = issues.map((i) => t(i.message, i.vars)).join(" · ")}
|
||||
<span class="relative z-[1] grid size-5 place-items-center text-warning" title={issueText}>
|
||||
<TriangleAlert class="size-3.5" />
|
||||
<span class="sr-only">{issueText}</span>
|
||||
</span>
|
||||
{/if}
|
||||
{:else if col.key === "name"}
|
||||
<span class="font-medium">
|
||||
{#if g.is_dead}<span title={t("games.deadTitle")} class="mr-1">💀</span>{/if}
|
||||
{g.name || "—"}
|
||||
</span>
|
||||
{#if g.is_dead}<span aria-hidden="true" title={t("games.deadTitle")} class="relative z-[1] mr-1">💀</span>{/if}
|
||||
<a
|
||||
href={appid ? `/games/${appid}` : g.link}
|
||||
class="font-medium after:absolute after:inset-0 after:content-[''] focus-visible:outline-none"
|
||||
>
|
||||
{g.name || "—"}{#if g.is_dead}<span class="sr-only">, {t("games.deadTitle")}</span>{/if}
|
||||
</a>
|
||||
{:else if col.key === "genre"}
|
||||
{#if g.genre}<Badge variant="outline">{g.genre}</Badge>{:else}<span class="text-muted-foreground">—</span>{/if}
|
||||
{:else if col.key === "type_game"}
|
||||
@@ -182,7 +209,7 @@
|
||||
<span class="font-mono tnum">{formatNumber(g.all_time_peak)}</span>
|
||||
{:else if col.key === "anti_cheat"}
|
||||
{#if g.anti_cheat && g.anti_cheat !== "-"}
|
||||
<Badge variant={g.is_kernel_ac ? "destructive" : "warning"}>{g.anti_cheat}</Badge>
|
||||
<AntiCheatBadge name={g.anti_cheat} kernel={g.is_kernel_ac} />
|
||||
{:else}<span class="text-muted-foreground">—</span>{/if}
|
||||
{:else if col.key === "platforms"}
|
||||
<span class="text-xs text-muted-foreground">
|
||||
@@ -195,36 +222,27 @@
|
||||
{t(g.status === "active" ? "common.active" : "common.delisted")}
|
||||
</Badge>
|
||||
{:else if col.key === "link"}
|
||||
<!-- stopPropagation so the Steam link does not also trigger
|
||||
the row navigation wrapping it. -->
|
||||
<span
|
||||
role="link"
|
||||
tabindex="0"
|
||||
<!-- A real link now that it is not nested inside the row's
|
||||
own link, so the apps' external-link interceptor opens it
|
||||
in the system browser like any other. Out of the Tab
|
||||
order: one stop per row, not two, and a game's own page
|
||||
has the same Steam links for the keyboard. Screen readers
|
||||
still find it. -->
|
||||
<a
|
||||
href={g.link}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
tabindex="-1"
|
||||
aria-label={t("games.openOnSteamNamed", { name: g.name || appid || "" })}
|
||||
title={t("detail.openOnSteam", { appid: appidOf(g) })}
|
||||
onclick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
// openExternal, not window.open: the Tauri webview blocks
|
||||
// window.open to external URLs, and the global link
|
||||
// interceptor only sees <a> elements - this is a span
|
||||
// inside the row's own internal link.
|
||||
void openExternal(g.link);
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
void openExternal(g.link);
|
||||
}
|
||||
}}
|
||||
class="inline-grid size-6 place-items-center text-muted-foreground hover:text-primary"
|
||||
class="relative z-[1] inline-grid size-6 place-items-center text-muted-foreground hover:text-primary"
|
||||
>
|
||||
<ExternalLink class="size-3.5" />
|
||||
</span>
|
||||
</a>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</a>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import { formatNumber, parseReviewPercent, cn } from "../utils";
|
||||
import { reviewTone } from "./columns";
|
||||
import Badge from "../ui/Badge.svelte";
|
||||
import AntiCheatBadge from "./AntiCheatBadge.svelte";
|
||||
|
||||
// Below md the 1,282px-wide table is unusable, so the same rows render as
|
||||
// cards. Still virtualised: 3,700 cards is as many DOM nodes as 3,700 rows.
|
||||
@@ -39,8 +40,11 @@
|
||||
const items = $derived($virtualizer.getVirtualItems());
|
||||
</script>
|
||||
|
||||
<div bind:this={viewport} class="h-[calc(100dvh-18rem)] overflow-auto scrollbar-slim scrollbar-panel">
|
||||
<div style:height="{$virtualizer.getTotalSize()}px" class="relative">
|
||||
<!-- min-h, as in GamesTable: at 300-400% zoom the window-sized height reached
|
||||
zero. A list with its size and each card's position, since only the cards
|
||||
on screen exist. -->
|
||||
<div bind:this={viewport} class="h-[calc(100dvh-18rem)] min-h-64 overflow-auto scrollbar-slim scrollbar-panel">
|
||||
<div role="list" aria-label={t("games.title")} style:height="{$virtualizer.getTotalSize()}px" class="relative">
|
||||
{#each items as item (item.key)}
|
||||
{@const g = rows[item.index]}
|
||||
{@const appid = appidOf(g)}
|
||||
@@ -50,62 +54,69 @@
|
||||
measuring), so a badge row that wrapped to a third line used to paint
|
||||
over the next card. The anti-cheat badge truncates instead of wrapping:
|
||||
some values run to 72 characters. -->
|
||||
<a
|
||||
href={appid ? `/games/${appid}` : g.link}
|
||||
class="absolute left-0 right-0 flex gap-3 overflow-hidden border-b px-1 py-3"
|
||||
<div
|
||||
role="listitem"
|
||||
aria-setsize={rows.length}
|
||||
aria-posinset={item.index + 1}
|
||||
class="absolute left-0 right-0"
|
||||
style:height="{item.size}px"
|
||||
style:transform="translateY({item.start}px)"
|
||||
>
|
||||
{#if g.header_image}
|
||||
<img
|
||||
src={headerToCapsule(g.header_image)}
|
||||
{@attach imgFallback(thumbFallback(g.header_image))}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
referrerpolicy="no-referrer"
|
||||
class="h-[42px] w-[90px] shrink-0 rounded object-cover"
|
||||
/>
|
||||
{:else}
|
||||
<div class="h-[42px] w-[90px] shrink-0 rounded bg-muted"></div>
|
||||
{/if}
|
||||
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-1.5">
|
||||
{#if g.is_dead}<span title={t("games.deadTitle")}>💀</span>{/if}
|
||||
<span class="truncate text-sm font-medium">{g.name || "—"}</span>
|
||||
{#if issues.length}
|
||||
<TriangleAlert
|
||||
class="size-3.5 shrink-0 text-warning"
|
||||
aria-label={issues.map((i) => t(i.message, i.vars)).join(" · ")}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="mt-1 flex flex-wrap items-center gap-1">
|
||||
{#if g.genre}<Badge variant="outline">{g.genre}</Badge>{/if}
|
||||
{#if g.type_game}
|
||||
<Badge variant={g.type_game === "online" ? "success" : "secondary"}>
|
||||
{t(g.type_game === "online" ? "common.online" : "common.offline")}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if g.anti_cheat && g.anti_cheat !== "-"}
|
||||
<Badge variant={g.is_kernel_ac ? "destructive" : "warning"} class="block max-w-full truncate">
|
||||
{g.anti_cheat}
|
||||
</Badge>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="shrink-0 text-right">
|
||||
{#if pct !== null}
|
||||
<div class={cn("font-mono text-sm tnum", reviewTone(pct))}>{pct}%</div>
|
||||
<a
|
||||
href={appid ? `/games/${appid}` : g.link}
|
||||
class="flex h-full gap-3 overflow-hidden border-b px-1 py-3"
|
||||
>
|
||||
{#if g.header_image}
|
||||
<img
|
||||
src={headerToCapsule(g.header_image)}
|
||||
{@attach imgFallback(thumbFallback(g.header_image))}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
referrerpolicy="no-referrer"
|
||||
class="h-[42px] w-[90px] shrink-0 rounded object-cover"
|
||||
/>
|
||||
{:else}
|
||||
<div class="h-[42px] w-[90px] shrink-0 rounded bg-muted"></div>
|
||||
{/if}
|
||||
<div class="font-mono text-xs text-muted-foreground tnum">
|
||||
{formatNumber(g.current_players)}
|
||||
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-1.5">
|
||||
{#if g.is_dead}<span aria-hidden="true" title={t("games.deadTitle")}>💀</span>{/if}
|
||||
<span class="truncate text-sm font-medium">
|
||||
{g.name || "—"}{#if g.is_dead}<span class="sr-only">, {t("games.deadTitle")}</span>{/if}
|
||||
</span>
|
||||
{#if issues.length}
|
||||
<TriangleAlert
|
||||
class="size-3.5 shrink-0 text-warning"
|
||||
aria-label={issues.map((i) => t(i.message, i.vars)).join(" · ")}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="mt-1 flex flex-wrap items-center gap-1">
|
||||
{#if g.genre}<Badge variant="outline">{g.genre}</Badge>{/if}
|
||||
{#if g.type_game}
|
||||
<Badge variant={g.type_game === "online" ? "success" : "secondary"}>
|
||||
{t(g.type_game === "online" ? "common.online" : "common.offline")}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if g.anti_cheat && g.anti_cheat !== "-"}
|
||||
<AntiCheatBadge name={g.anti_cheat} kernel={g.is_kernel_ac} class="block max-w-full truncate" />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<div class="shrink-0 text-right">
|
||||
{#if pct !== null}
|
||||
<div class={cn("font-mono text-sm tnum", reviewTone(pct))}>{pct}%</div>
|
||||
{/if}
|
||||
<div class="font-mono text-xs text-muted-foreground tnum">
|
||||
{formatNumber(g.current_players)}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
@@ -33,6 +33,9 @@ export interface ColDef {
|
||||
key: ColumnKey;
|
||||
/** i18n key, or "" for the icon-only columns. */
|
||||
label: string;
|
||||
/** i18n key read only by screen readers, for the icon-only columns: an
|
||||
* empty column header leaves every cell under it unnamed. */
|
||||
srLabel?: string;
|
||||
width: number;
|
||||
sortable?: boolean;
|
||||
align?: "left" | "right" | "center";
|
||||
@@ -40,8 +43,8 @@ export interface ColDef {
|
||||
}
|
||||
|
||||
export const COLS: ColDef[] = [
|
||||
{ key: "thumb", label: "", width: 64 },
|
||||
{ key: "issues", label: "", width: 30 },
|
||||
{ key: "thumb", label: "", srLabel: "games.colImage", width: 64 },
|
||||
{ key: "issues", label: "", srLabel: "games.colIssues", width: 30 },
|
||||
{
|
||||
key: "name",
|
||||
label: "games.colName",
|
||||
@@ -113,7 +116,7 @@ export const COLS: ColDef[] = [
|
||||
sortable: true,
|
||||
sortValue: (g) => g.status ?? "",
|
||||
},
|
||||
{ key: "link", label: "", width: 48 },
|
||||
{ key: "link", label: "", srLabel: "games.colSteam", width: 48 },
|
||||
];
|
||||
|
||||
export const TOTAL_WIDTH = COLS.reduce((sum, c) => sum + c.width, 0);
|
||||
|
||||
Reference in new issue
Block a user