Check the active sort in the gallery sort menu (#4998)

* Check the active sort in the gallery sort menu

The grid toolbar's sort menu (and its phone-width mirror) marked the
active axis by colour alone. It now also shows a leading check, the same
way the version switcher and sibling menus mark the current item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

* Share the sort menu's selection mark and test the phone menu

Both sort menus now take their active variant and check from one
selectionMark helper, and the toolbar test covers the phone-width menu
as well as the inline one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

* Reset the toolbar test's breakpoint in teardown and drop a restating comment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sam Dornan
2026-10-01 13:54:05 -04:00
committed by GitHub
parent bf42ac0422
commit 97a5f80eef
2 changed files with 27 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import { mount } from "@vue/test-utils";
import { describe, expect, it, vi } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";
import { ref } from "vue";
import GalleryToolbar from "./GalleryToolbar.vue";
@@ -7,8 +7,9 @@ vi.mock("vue-i18n", () => ({
useI18n: () => ({ t: (key: string) => key }),
}));
const smAndUp = ref(true);
vi.mock("@/v2/composables/useBreakpoint", () => ({
useBreakpoint: () => ({ smAndUp: ref(true) }),
useBreakpoint: () => ({ smAndUp }),
}));
const modality = ref<"mouse" | "pad">("mouse");
@@ -88,6 +89,10 @@ describe("GalleryToolbar search autofocus", () => {
});
describe("GalleryToolbar sort axis", () => {
afterEach(() => {
smAndUp.value = true;
});
it("emits the picked axis so grid mode can change the sort key", async () => {
const wrapper = mountWithSortOptions();
@@ -101,17 +106,24 @@ describe("GalleryToolbar sort axis", () => {
wrapper.unmount();
});
it("marks the active axis", () => {
it.each([
["the toolbar menu", true],
["the phone-width menu", false],
])("marks the active axis with a check in %s", (_, wide) => {
smAndUp.value = wide;
const wrapper = mountWithSortOptions({ sortKey: "fs_size_bytes" });
const variants = Object.fromEntries(
const marks = Object.fromEntries(
sortItems(wrapper).map((item) => [
item.props("label"),
item.props("variant"),
[item.props("variant"), item.props("icon")],
]),
);
expect(variants).toMatchObject({ Size: "active", Title: "default" });
expect(marks).toEqual({
Size: ["active", "mdi-check"],
Title: ["default", undefined],
});
wrapper.unmount();
});

View File

@@ -232,6 +232,13 @@ function setSortDir(value: "asc" | "desc") {
emit("update:sortDir", value);
}
function selectionMark(selected: boolean) {
return {
variant: selected ? ("active" as const) : ("default" as const),
icon: selected ? "mdi-check" : undefined,
};
}
function setSortKey(value: ListSortKey) {
emit("update:sortKey", value);
}
@@ -350,7 +357,7 @@ const { smAndUp } = useBreakpoint();
v-for="item in sortKeyItems"
:key="item.key"
:label="item.label"
:variant="sortKeyValue === item.key ? 'active' : 'default'"
v-bind="selectionMark(sortKeyValue === item.key)"
@click="setSortKey(item.key)"
/>
</RMenu>
@@ -422,7 +429,7 @@ const { smAndUp } = useBreakpoint();
v-for="item in sortKeyItems"
:key="item.key"
:label="item.label"
:variant="sortKeyValue === item.key ? 'active' : 'default'"
v-bind="selectionMark(sortKeyValue === item.key)"
@click="setSortKey(item.key)"
/>
<RDivider v-if="sortKeyItems.length > 0" />