mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 02:22:44 +01:00
fix(v2): address code-review findings on the mobile subtabs
pr-ready step 2 (code-review xhigh --fix): restore the pill gap and a zero min-width on RTabNav, keep chevron clicks from stealing focus, scroll a keyboard-focused tab clear of the fade, paint the subtab focus ring inside the button, and cover SubtabNav and the patch either-or rule with tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CZ7NE6z9cJ8zsT3TsCtQds
This commit is contained in:
@@ -617,11 +617,8 @@ async function refreshRom() {
|
||||
</aside>
|
||||
|
||||
<div class="r-v2-files__content">
|
||||
<!-- Section header: the subtab nav already names the section, so the
|
||||
header skips a redundant title and just hosts the upload action on
|
||||
the right (next to the folder picker on phones). Download-all /
|
||||
Copy-link are covered by the selection toolbar below (select-all
|
||||
then act). -->
|
||||
<!-- No title: the subtab nav already names the section. Bulk download
|
||||
and copy-link live in the selection toolbar below. -->
|
||||
<header
|
||||
v-if="smAndDown || (filteredFiles.length > 0 && canUpload)"
|
||||
class="r-v2-files__section-head"
|
||||
|
||||
@@ -41,7 +41,7 @@ vi.mock("@/v2/composables/useSnackbar", () => ({
|
||||
|
||||
const RSelect = {
|
||||
props: {
|
||||
modelValue: { type: String, default: "" },
|
||||
modelValue: { type: [String, Object], default: "" },
|
||||
items: { type: Array, default: () => [] },
|
||||
},
|
||||
emits: ["update:modelValue"],
|
||||
@@ -53,6 +53,8 @@ const RBtn = {
|
||||
template: `<button :disabled="disabled" @click="$emit('click')"><slot /></button>`,
|
||||
};
|
||||
|
||||
const APPLY = 'button[prepend-icon="mdi-file-cog"]';
|
||||
|
||||
const archiveMembers: RomArchiveMember[] = [
|
||||
{
|
||||
name: "docs/readme.txt",
|
||||
@@ -106,8 +108,8 @@ describe("PatcherTab", () => {
|
||||
vi.spyOn(HTMLAnchorElement.prototype, "click").mockImplementation(() => {});
|
||||
});
|
||||
|
||||
it("sends the selected ZIP member when applying a patch", async () => {
|
||||
const wrapper = mount(PatcherTab, {
|
||||
function mountTab() {
|
||||
return mount(PatcherTab, {
|
||||
props: { rom: rom() },
|
||||
global: {
|
||||
stubs: {
|
||||
@@ -119,7 +121,6 @@ describe("PatcherTab", () => {
|
||||
RIcon: true,
|
||||
RPlatformIcon: true,
|
||||
RSelect,
|
||||
RSliderBtnGroup: true,
|
||||
RTextField: true,
|
||||
RTooltip: true,
|
||||
MissingFSBadge: true,
|
||||
@@ -127,8 +128,12 @@ describe("PatcherTab", () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const applyButton = wrapper.get("button");
|
||||
it("sends the selected ZIP member when applying a patch", async () => {
|
||||
const wrapper = mountTab();
|
||||
|
||||
const applyButton = wrapper.get(APPLY);
|
||||
expect(applyButton.attributes("disabled")).toBeDefined();
|
||||
|
||||
await wrapper.get("select").setValue("roms/Super Metroid.sfc");
|
||||
@@ -143,4 +148,33 @@ describe("PatcherTab", () => {
|
||||
"roms/Super Metroid.sfc",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps an uploaded patch and a bundled one mutually exclusive", async () => {
|
||||
const wrapper = mountTab();
|
||||
await wrapper.get("select").setValue("roms/Super Metroid.sfc");
|
||||
const upload = new File(["ips"], "hack.ips");
|
||||
|
||||
wrapper.findComponent({ name: "RDropzone" }).vm.$emit("files", [upload]);
|
||||
await wrapper.vm.$nextTick();
|
||||
expect(wrapper.find(".r-v2-patch__uploaded").exists()).toBe(true);
|
||||
await wrapper.get(APPLY).trigger("click");
|
||||
await flushPromises();
|
||||
|
||||
const uploadForm = post.mock.calls[0][1] as FormData;
|
||||
expect(uploadForm.get("patch_file")).toBeInstanceOf(File);
|
||||
expect(uploadForm.get("patch_file_id")).toBeNull();
|
||||
|
||||
const bundled = rom().files[1];
|
||||
wrapper
|
||||
.findAllComponents(RSelect)[1]
|
||||
.vm.$emit("update:modelValue", bundled);
|
||||
await wrapper.vm.$nextTick();
|
||||
expect(wrapper.find(".r-v2-patch__uploaded").exists()).toBe(false);
|
||||
await wrapper.get(APPLY).trigger("click");
|
||||
await flushPromises();
|
||||
|
||||
const bundledForm = post.mock.calls[1][1] as FormData;
|
||||
expect(bundledForm.get("patch_file")).toBeNull();
|
||||
expect(bundledForm.get("patch_file_id")).toBe("11");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -760,14 +760,12 @@ const applyLabel = computed(() => {
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* Single-file display (no picker) — name + size chip. */
|
||||
.r-v2-patch__or {
|
||||
color: var(--r-color-fg-muted);
|
||||
font-size: var(--r-font-size-xs);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.1em;
|
||||
}
|
||||
|
||||
/* Single-file display (no picker): name + size chip. */
|
||||
.r-v2-patch__file-single {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
79
frontend/src/v2/components/GameDetails/SubtabNav.test.ts
Normal file
79
frontend/src/v2/components/GameDetails/SubtabNav.test.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import SubtabNav, { type SubtabNavItem } from "./SubtabNav.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
|
||||
const RMenu = {
|
||||
props: { searchable: { type: Boolean, default: false } },
|
||||
emits: ["update:search", "update:modelValue"],
|
||||
template: `<div class="menu" :data-searchable="searchable"><slot name="activator" :props="{}" /><slot /></div>`,
|
||||
};
|
||||
const RMenuItem = {
|
||||
props: { label: { type: String, default: "" } },
|
||||
emits: ["click"],
|
||||
template: `<button class="option" @click="$emit('click')">{{ label }}<slot name="append" /></button>`,
|
||||
};
|
||||
|
||||
const stubs = {
|
||||
RBtn: { template: `<button class="trigger"><slot /></button>` },
|
||||
RDivider: true,
|
||||
RIcon: true,
|
||||
RMenu,
|
||||
RMenuItem,
|
||||
};
|
||||
|
||||
function nav(items: SubtabNavItem[], props: Record<string, unknown> = {}) {
|
||||
return mount(SubtabNav, {
|
||||
props: { modelValue: items[0].id, items, ...props },
|
||||
global: { stubs },
|
||||
});
|
||||
}
|
||||
|
||||
describe("SubtabNav", () => {
|
||||
it("heads each group once and hides a zero badge", () => {
|
||||
const wrapper = nav([
|
||||
{ id: "a", label: "Alpha", group: "Mine", badge: 0 },
|
||||
{ id: "b", label: "Beta", group: "Mine", badge: 3 },
|
||||
{ id: "c", label: "Gamma", group: "Community" },
|
||||
]);
|
||||
|
||||
expect(
|
||||
wrapper.findAll(".r-v2-subtab-nav__group").map((g) => g.text()),
|
||||
).toEqual(["Mine", "Community"]);
|
||||
expect(
|
||||
wrapper.findAll(".r-v2-subtab-nav__badge").map((b) => b.text()),
|
||||
).toEqual(["3"]);
|
||||
});
|
||||
|
||||
it("emits only when a different subtab is picked", async () => {
|
||||
const wrapper = nav([
|
||||
{ id: "a", label: "Alpha" },
|
||||
{ id: "b", label: "Beta" },
|
||||
]);
|
||||
const buttons = wrapper.findAll(".r-v2-subtab-nav__btn");
|
||||
|
||||
await buttons[0].trigger("click");
|
||||
expect(wrapper.emitted("update:modelValue")).toBeUndefined();
|
||||
await buttons[1].trigger("click");
|
||||
expect(wrapper.emitted("update:modelValue")).toEqual([["b"]]);
|
||||
});
|
||||
|
||||
it("offers a filter past eight entries and matches labels loosely", async () => {
|
||||
const items = Array.from({ length: 9 }, (_, i) => ({
|
||||
id: `n${i}`,
|
||||
label: i === 4 ? "Speedrun Route" : `Note ${i}`,
|
||||
}));
|
||||
const wrapper = nav(items, { variant: "menu" });
|
||||
const menu = wrapper.findComponent(RMenu);
|
||||
|
||||
expect(menu.attributes("data-searchable")).toBe("true");
|
||||
menu.vm.$emit("update:search", " ROUTE ");
|
||||
await wrapper.vm.$nextTick();
|
||||
expect(wrapper.findAll(".option").map((o) => o.text())).toEqual([
|
||||
"Speedrun Route",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -226,6 +226,14 @@ function select(id: T) {
|
||||
background: color-mix(in srgb, var(--r-color-brand-primary) 18%, transparent);
|
||||
color: var(--r-color-brand-primary);
|
||||
}
|
||||
/* The list is a scroll container that clips the global outline ring, so paint
|
||||
the key / pad focus inside the button instead. */
|
||||
html:not([data-input]) .r-v2-subtab-nav__btn:focus-visible,
|
||||
html[data-input="key"] .r-v2-subtab-nav__btn:focus-visible,
|
||||
html[data-input="pad"] .r-v2-subtab-nav__btn:focus-visible {
|
||||
outline: none;
|
||||
box-shadow: inset 0 0 0 2px var(--r-color-focus);
|
||||
}
|
||||
.r-v2-subtab-nav__label {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@@ -115,9 +115,8 @@ function updateOverflow() {
|
||||
overflowEnd.value = track.scrollLeft < maxScroll - 1;
|
||||
}
|
||||
|
||||
function revealActive(behavior: ScrollBehavior) {
|
||||
function reveal(el: HTMLElement | null | undefined, behavior: ScrollBehavior) {
|
||||
const track = trackEl.value;
|
||||
const el = btnEls.get(props.modelValue);
|
||||
if (!track || !el || props.orientation !== "horizontal") return;
|
||||
const start = el.offsetLeft - EDGE_PX;
|
||||
const end = el.offsetLeft + el.offsetWidth + EDGE_PX - track.clientWidth;
|
||||
@@ -128,6 +127,16 @@ function revealActive(behavior: ScrollBehavior) {
|
||||
}
|
||||
}
|
||||
|
||||
function revealActive(behavior: ScrollBehavior) {
|
||||
reveal(btnEls.get(props.modelValue), behavior);
|
||||
}
|
||||
|
||||
// The browser's own focus scroll stops at the edge, under the fade and chevron.
|
||||
function onTrackFocusIn(event: FocusEvent) {
|
||||
const el = event.target as HTMLElement;
|
||||
if (el.matches(":focus-visible")) reveal(el, scrollBehavior());
|
||||
}
|
||||
|
||||
function scrollPage(direction: 1 | -1) {
|
||||
const track = trackEl.value;
|
||||
if (!track) return;
|
||||
@@ -228,6 +237,7 @@ onBeforeUnmount(() => {
|
||||
ref="trackEl"
|
||||
class="r-tab-nav__track"
|
||||
@scroll.passive="updateOverflow"
|
||||
@focusin="onTrackFocusIn"
|
||||
>
|
||||
<button
|
||||
v-for="t in visibleItems"
|
||||
@@ -280,6 +290,7 @@ onBeforeUnmount(() => {
|
||||
tabindex="-1"
|
||||
aria-hidden="true"
|
||||
class="r-tab-nav__edge r-tab-nav__edge--start"
|
||||
@mousedown.prevent
|
||||
@click="scrollPage(-1)"
|
||||
>
|
||||
<RIcon icon="mdi-chevron-left" size="18" />
|
||||
@@ -290,6 +301,7 @@ onBeforeUnmount(() => {
|
||||
tabindex="-1"
|
||||
aria-hidden="true"
|
||||
class="r-tab-nav__edge r-tab-nav__edge--end"
|
||||
@mousedown.prevent
|
||||
@click="scrollPage(1)"
|
||||
>
|
||||
<RIcon icon="mdi-chevron-right" size="18" />
|
||||
@@ -300,6 +312,9 @@ onBeforeUnmount(() => {
|
||||
<style scoped>
|
||||
.r-tab-nav {
|
||||
position: relative;
|
||||
/* The track scrolls, not the nav, so without this a flex or grid parent
|
||||
sizes the nav to every tab and the strip overflows instead of scrolling. */
|
||||
min-width: 0;
|
||||
}
|
||||
.r-tab-nav__track {
|
||||
display: flex;
|
||||
@@ -387,9 +402,8 @@ onBeforeUnmount(() => {
|
||||
the button's own background. The underlined variant raises this to 1. */
|
||||
position: relative;
|
||||
z-index: 0;
|
||||
/* Keep natural width so the horizontal nav scrolls on overflow
|
||||
(`.r-tab-nav--horizontal { overflow-x: auto }`) instead of squishing
|
||||
the tabs below their content on narrow viewports. */
|
||||
/* Keep natural width so the horizontal track scrolls on overflow
|
||||
instead of squishing the tabs below their content on narrow viewports. */
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -428,7 +442,7 @@ onBeforeUnmount(() => {
|
||||
|
||||
/* ---------- Focus ----------
|
||||
The global modality-gated ring (global.css) is an `outline`, which the
|
||||
nav's `overflow-y: hidden` clip slices into two vertical slivers on
|
||||
track's `overflow-y: hidden` clip slices into two vertical slivers on
|
||||
either side of the focused tab. Suppress it and paint a contained,
|
||||
rounded highlight that lives INSIDE the button (a pseudo-element, so
|
||||
nothing can be clipped away). Gated to keyboard / pad exactly like the
|
||||
@@ -506,7 +520,7 @@ html[data-input="pad"] .r-tab-nav__btn:focus-visible::before {
|
||||
}
|
||||
|
||||
/* ---------- Pill variant ---------- */
|
||||
.r-tab-nav--pill {
|
||||
.r-tab-nav--pill .r-tab-nav__track {
|
||||
gap: 4px;
|
||||
}
|
||||
.r-tab-nav--pill .r-tab-nav__btn {
|
||||
|
||||
Reference in New Issue
Block a user