Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8908: fix(skills): restore typing in the Labels filter search (#10253)

Jiayuan Zhang251e20de4990
diff --git a/packages/views/skills/components/skill-list-controls.label-search.test.tsx b/packages/views/skills/components/skill-list-controls.label-search.test.tsx
new file mode 100644
index 0000000000..9472538553
--- /dev/null
+++ b/packages/views/skills/components/skill-list-controls.label-search.test.tsx
@@ -0,0 +1,86 @@
+// @vitest-environment jsdom
+
+/**
+ * The Labels search inside the Skills page's Filter menu, driven against the
+ * REAL Base UI menu primitives: the menu popup's typeahead stopEvent()s every
+ * printable key, so without a keyboard guard on the search box it swallowed
+ * every character. Same defect and guard as the issues Filter menu — see
+ * issues/components/issues-header.advanced-filter.test.tsx.
+ */
+
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { cleanup, screen, waitFor } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { setApiInstance } from "@multica/core/api";
+import type { ApiClient } from "@multica/core/api/client";
+import { EMPTY_SKILL_FILTERS } from "@multica/core/skills/stores";
+import type { Label } from "@multica/core/types";
+import { renderWithI18n } from "../../test/i18n";
+import { SkillFilterMenu } from "./skill-list-controls";
+
+vi.mock("@multica/core/hooks", () => ({
+ useWorkspaceId: () => "ws-1",
+}));
+// The label catalog dialog is mounted closed; it is not what this exercises.
+vi.mock("../../labels/label-manager", () => ({
+ LabelManager: () => null,
+}));
+
+const LABELS = [
+ { id: "l-bug", workspace_id: "ws-1", name: "bug", color: "#ef4444" },
+ { id: "l-docs", workspace_id: "ws-1", name: "docs", color: "#3b82f6" },
+] as unknown as Label[];
+
+function renderFilterMenu() {
+ setApiInstance({
+ listLabels: async () => ({ labels: LABELS, total: LABELS.length }),
+ } as unknown as ApiClient);
+ const qc = new QueryClient({
+ defaultOptions: { queries: { retry: false, staleTime: Infinity } },
+ });
+ return renderWithI18n(
+ <QueryClientProvider client={qc}>
+ <SkillFilterMenu
+ filters={EMPTY_SKILL_FILTERS}
+ onToggleFilter={() => {}}
+ rows={[]}
+ />
+ </QueryClientProvider>,
+ );
+}
+
+afterEach(() => {
+ cleanup();
+ // Base UI portals the menu onto document.body.
+ document.body.innerHTML = "";
+ vi.restoreAllMocks();
+});
+
+describe("SkillFilterMenu label filter search", () => {
+ it("types into the Labels search and narrows the list", async () => {
+ renderFilterMenu();
+ const user = userEvent.setup();
+ await user.click(screen.getByRole("button", { name: /^Filter/ }));
+ await user.click(await screen.findByRole("menuitem", { name: /^Labels/ }));
+ await waitFor(() =>
+ expect(screen.getByRole("menuitemcheckbox", { name: /docs/ })).toBeInTheDocument(),
+ );
+ const input = screen.getByPlaceholderText("Filter...");
+ expect(input).toHaveFocus();
+
+ await user.keyboard("doc");
+
+ expect(input).toHaveValue("doc");
+ expect(screen.getByRole("menuitemcheckbox", { name: /docs/ })).toBeInTheDocument();
+ expect(screen.queryByRole("menuitemcheckbox", { name: /bug/ })).toBeNull();
+
+ // Left/right/Home/End edit the query instead of closing the submenu.
+ await user.keyboard("{ArrowLeft}{Home}{End}{Backspace}");
+ expect(input).toHaveValue("do");
+ expect(input).toHaveFocus();
+
+ await user.keyboard("{Escape}");
+ await waitFor(() => expect(screen.queryByPlaceholderText("Filter...")).not.toBeInTheDocument());
+ });
+});
diff --git a/packages/views/skills/components/skill-list-controls.tsx b/packages/views/skills/components/skill-list-controls.tsx
index 0c90218670..b05df3099c 100644
--- a/packages/views/skills/components/skill-list-controls.tsx
+++ b/packages/views/skills/components/skill-list-controls.tsx
@@ -33,6 +33,7 @@ import {
DialogTitle,
} from "@multica/ui/components/ui/dialog";
import { FILTER_ITEM_CLASS, HoverCheck } from "../../common/hover-check";
+import { stopMenuSearchKeys } from "../../issues/components/advanced-filter-panel";
import {
type SkillListFilters,
type SkillOriginType,
@@ -276,6 +277,7 @@ export function SkillFilterMenu({
type="text"
value={labelSearch}
onChange={(e) => setLabelSearch(e.target.value)}
+ onKeyDown={stopMenuSearchKeys}
placeholder={t(($) => $.toolbar.filter_search_placeholder)}
className="w-full bg-transparent text-body outline-none placeholder:text-muted-foreground"
autoFocus