From 00d6584bdd2815eecd2717862c03dd9c93f25c54 Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 18 Nov 2026 05:15:58 +0000 Subject: [PATCH 01/11] Ignore row clicks that come from the row's portalled menu or dialog (#66, 5.1) Co-Authored-By: Claude Opus 5.5 --- .changeset/row-click-portals.md | 5 +++++ .../onu/src/components/listing/_collection.tsx | 4 ++-- .../onu/src/components/listing/_shared.tsx | 14 ++++++++++---- .../src/components/listing/data-table.test.tsx | 16 ++++++++++++++++ .../onu/src/components/listing/data-table.tsx | 4 ++-- .../onu/src/components/listing/views.test.tsx | 18 ++++++++++++++++++ 6 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 .changeset/row-click-portals.md diff --git a/.changeset/row-click-portals.md b/.changeset/row-click-portals.md new file mode 100644 index 00000000..283c9e3d --- /dev/null +++ b/.changeset/row-click-portals.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": patch +--- + +Clicking inside a row's actions menu or confirm dialog no longer opens the row in `DataTable`, `ListView` and the other collection views. diff --git a/packages/onu/src/components/listing/_collection.tsx b/packages/onu/src/components/listing/_collection.tsx index 9b894777..2ba0465b 100644 --- a/packages/onu/src/components/listing/_collection.tsx +++ b/packages/onu/src/components/listing/_collection.tsx @@ -3,7 +3,7 @@ import * as React from "react" import { useLinkComponent, useTranslation } from "../../providers/onu-provider" -import { isInteractiveTarget } from "./_shared" +import { ignoresRowClick } from "./_shared" import { SelectionCheckbox } from "./_selection-checkbox" // The dropdown on its own: row menus never open as context menus, so tables don't bundle one. import { DropdownActionMenu as ActionMenu } from "../overlays/_action-menu" @@ -90,7 +90,7 @@ export function useCollectionItem(props: CollectionProps) { const clickable = !!props.onItemClick || !!href const onClick = clickable ? (event: React.MouseEvent) => { - if (isInteractiveTarget(event.target, event.currentTarget)) return + if (ignoresRowClick(event)) return if (props.onItemClick) props.onItemClick(item) else event.currentTarget.querySelector("a[data-row-link]")?.click() } diff --git a/packages/onu/src/components/listing/_shared.tsx b/packages/onu/src/components/listing/_shared.tsx index 5e2fe269..379ea67e 100644 --- a/packages/onu/src/components/listing/_shared.tsx +++ b/packages/onu/src/components/listing/_shared.tsx @@ -24,10 +24,16 @@ export function useNoun(noun: ListingNoun | undefined) { ) } -/** Whether a click landed on (or inside) an interactive element, so row clicks can ignore it. */ -export function isInteractiveTarget(target: EventTarget | null, stopAt?: Element | null) { - let el = target instanceof Element ? target : null - while (el && el !== stopAt) { +/** + * Whether a row's click handler should ignore this click: it landed on (or inside) an interactive + * element, or outside the row's DOM altogether. React bubbles events from portals (the row's ⋯ menu, + * its confirm dialog) through the component tree, so those clicks reach the row too. + */ +export function ignoresRowClick(event: React.MouseEvent) { + const row = event.currentTarget + let el = event.target instanceof Element ? event.target : null + if (!el || !row.contains(el)) return true + while (el && el !== row) { if ( el.matches( "a,button,input,select,textarea,label,summary,[role=button],[role=checkbox],[role=menuitem],[role=switch],[contenteditable=true]", diff --git a/packages/onu/src/components/listing/data-table.test.tsx b/packages/onu/src/components/listing/data-table.test.tsx index b4f34c4f..51ecc367 100644 --- a/packages/onu/src/components/listing/data-table.test.tsx +++ b/packages/onu/src/components/listing/data-table.test.tsx @@ -276,6 +276,22 @@ describe("DataTable", () => { expect(onDelete).toHaveBeenCalledWith("1") }) + it("ignores clicks inside the row's portalled menu and confirm dialog", async () => { + const onRowClick = vi.fn() + renderWithOnu( + [{ id: "delete", label: "Delete", destructive: true, onSelect: vi.fn() }]} + />, + ) + await userEvent.click(screen.getByRole("button", { name: "Actions for Jane Doe" })) + await userEvent.click(await screen.findByRole("menuitem", { name: "Delete" })) + const dialog = await screen.findByRole("alertdialog", { name: "Delete Jane Doe?" }) + await userEvent.click(within(dialog).getByRole("heading", { name: "Delete Jane Doe?" })) + expect(onRowClick).not.toHaveBeenCalled() + }) + it("opens the record when the row or its name is clicked (§25.6)", async () => { const onRowClick = vi.fn() const { unmount } = renderWithOnu( diff --git a/packages/onu/src/components/listing/data-table.tsx b/packages/onu/src/components/listing/data-table.tsx index 1b211108..77226e8d 100644 --- a/packages/onu/src/components/listing/data-table.tsx +++ b/packages/onu/src/components/listing/data-table.tsx @@ -23,7 +23,7 @@ import { cn } from "../../lib/utils" import { useLinkComponent, useTranslation } from "../../providers/onu-provider" import { Skeleton } from "../../ui/skeleton" import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "../../ui/table" -import { isInteractiveTarget } from "./_shared" +import { ignoresRowClick } from "./_shared" import { SelectionCheckbox } from "./_selection-checkbox" import { SortMenu } from "./_sort-menu" import { formatFilterLabel, useActiveFilterChips } from "./active-filter-chips" @@ -283,7 +283,7 @@ export function DataTable({ const headerChecked: boolean | "indeterminate" = allSelected ? true : someSelected ? "indeterminate" : false const openRow = (row: T, event: React.MouseEvent) => { - if (isInteractiveTarget(event.target, event.currentTarget)) return + if (ignoresRowClick(event)) return if (window.getSelection?.()?.toString()) return if (onRowClick) onRowClick(row) else if (getRowHref?.(row)) event.currentTarget.querySelector("a[data-row-link]")?.click() diff --git a/packages/onu/src/components/listing/views.test.tsx b/packages/onu/src/components/listing/views.test.tsx index 55672cf9..79907beb 100644 --- a/packages/onu/src/components/listing/views.test.tsx +++ b/packages/onu/src/components/listing/views.test.tsx @@ -61,6 +61,24 @@ describe.each(["list", "grid"] as const)("ListView layout=%s", (layout) => { expect(onItemClick).toHaveBeenCalledWith(users[2]) }) + it("ignores clicks inside the item's portalled confirm dialog", async () => { + const onItemClick = vi.fn() + renderWithOnu( + u.name} + onItemClick={onItemClick} + itemActions={() => [{ id: "delete", label: "Delete", destructive: true, onSelect: vi.fn() }]} + />, + ) + await userEvent.click(screen.getByRole("button", { name: "Actions for Jane Doe" })) + await userEvent.click(await screen.findByRole("menuitem", { name: "Delete" })) + const dialog = await screen.findByRole("alertdialog", { name: "Delete Jane Doe?" }) + await userEvent.click(within(dialog).getByRole("heading", { name: "Delete Jane Doe?" })) + expect(onItemClick).not.toHaveBeenCalled() + }) + it("follows the link when the item is clicked", async () => { const clicked = vi.fn((e: Event) => e.preventDefault()) renderWithOnu( From a2116bb22c140f4b1dc6c1ac513f4216db81e89e Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 18 Nov 2026 05:17:20 +0000 Subject: [PATCH 02/11] Build Pagination links from the paginator's own URLs (#66, 5.2) Co-Authored-By: Claude Opus 5.5 --- .changeset/pagination-server-links.md | 5 ++ docs/listing-pages/pagination.md | 1 + .../components/listing/pagination.test.tsx | 33 ++++++++ .../onu/src/components/listing/pagination.tsx | 76 +++++++++++++++---- 4 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 .changeset/pagination-server-links.md diff --git a/.changeset/pagination-server-links.md b/.changeset/pagination-server-links.md new file mode 100644 index 00000000..71ae2313 --- /dev/null +++ b/.changeset/pagination-server-links.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": patch +--- + +`Pagination` builds page links from the URLs a Laravel paginator sends, so the query string (search, filters) and a custom `pageName` are kept instead of being replaced by `path?page=N`. diff --git a/docs/listing-pages/pagination.md b/docs/listing-pages/pagination.md index 303b47a0..078310f6 100644 --- a/docs/listing-pages/pagination.md +++ b/docs/listing-pages/pagination.md @@ -25,6 +25,7 @@ import { Pagination } from "@javaabu/onu" - Previous is disabled on the first page and Next on the last (or when a simple paginator has no `next_page_url`). - With numbered pages the previous and next buttons are icon-only (their accessible names stay "Go to previous page" / "Go to next page"). Without a total (simple paginators) or with `numbered={false}` they show their labels. - With `getPageHref`, or a paginator with a `path` / `links`, pages are links rendered with `OnuProvider linkComponent` (Inertia, Next). Plain clicks still call `onPageChange` when given. +- Page links from a paginator come from the URLs the server sent (`links`, `first_page_url`, `prev_page_url`, …), so the query string from `->withQueryString()` and a custom `pageName` are kept. Pages the server didn't list swap the page number in one of those URLs; `path` is used only when the server sent no URLs. ## Props diff --git a/packages/onu/src/components/listing/pagination.test.tsx b/packages/onu/src/components/listing/pagination.test.tsx index 1dcd0396..b5d790bf 100644 --- a/packages/onu/src/components/listing/pagination.test.tsx +++ b/packages/onu/src/components/listing/pagination.test.tsx @@ -123,6 +123,39 @@ describe("Pagination", () => { expect(screen.getByRole("button", { name: "Go to next page" })).toBeDisabled() }) + it("keeps the server's query string and page name in page links", () => { + const url = (n: number) => `/users?search=ali&users_page=${n}` + renderWithOnu( + , + ) + expect(screen.getByRole("link", { name: "Go to next page" })).toHaveAttribute("href", url(3)) + expect(screen.getByRole("link", { name: "Go to previous page" })).toHaveAttribute("href", url(1)) + expect(screen.getByRole("link", { name: "Go to page 10" })).toHaveAttribute("href", url(10)) + // Page 4 isn't in `links[]`; it is built from the server's URLs, not from `path`. + expect(screen.getByRole("link", { name: "Go to page 4" })).toHaveAttribute("href", url(4)) + }) + it("uses hasNextPage when the total is unknown", () => { renderWithOnu() expect(screen.getByRole("button", { name: "Go to next page" })).toBeEnabled() diff --git a/packages/onu/src/components/listing/pagination.tsx b/packages/onu/src/components/listing/pagination.tsx index b22db94a..8f007b4d 100644 --- a/packages/onu/src/components/listing/pagination.tsx +++ b/packages/onu/src/components/listing/pagination.tsx @@ -25,6 +25,8 @@ export interface LaravelPaginationMeta { from?: number | null to?: number | null path?: string + first_page_url?: string | null + last_page_url?: string | null next_page_url?: string | null prev_page_url?: string | null links?: LaravelPaginatorLink[] | LaravelResourceLinks @@ -63,14 +65,53 @@ export interface PaginationInfo { to?: number prevUrl?: string | null nextUrl?: string | null - /** Builds the URL of any page, when the server gave a `path`. */ - pageUrl?: (page: number) => string + /** + * The URL of a page, built from the URLs the server sent (keeping its query string and page + * name), or from `path` when it sent none. Undefined when neither tells how to reach that page. + */ + pageUrl?: (page: number) => string | undefined } function isResource(input: LaravelResourceCollection | LaravelPaginationMeta): input is LaravelResourceCollection { return "meta" in input && typeof input.meta === "object" && input.meta !== null } +/** Page number of a `links[]` entry: Laravel 11+ sends `page`, older versions only the label. */ +function linkPage(link: LaravelPaginatorLink) { + if (typeof link.page === "number") return link.page + return /^\d+$/.test(link.label.trim()) ? Number(link.label.trim()) : undefined +} + +/** + * Builds page URLs from the URLs a Laravel paginator sent. Those carry the query string + * (`->withQueryString()`) and a custom `pageName`, which `path` alone loses: a page the server + * listed uses its URL as is, any other swaps the page number in one of them. + */ +function serverPageUrl(known: Map, path: string | undefined) { + const absolute = (url: string) => /^[a-z][a-z\d+.-]*:/i.test(url) + const build = (template: string, param: string, n: number) => { + const url = new URL(template, "http://localhost") + url.searchParams.set(param, String(n)) + return absolute(template) ? url.toString() : `${url.pathname}${url.search}${url.hash}` + } + // The page parameter is the one whose value tracks the page number in every known URL. + let template: { url: string; param: string } | undefined + const entries = [...known] + const [first] = entries + if (first) { + const params = [...new URL(first[1], "http://localhost").searchParams.keys()] + const param = params + .filter((key) => + entries.every(([n, url]) => new URL(url, "http://localhost").searchParams.get(key) === String(n)), + ) + .sort((a, b) => Number(b === "page") - Number(a === "page"))[0] + if (param) template = { url: first[1], param } + } + if (!template && path) template = { url: path, param: "page" } + if (!known.size && !template) return undefined + return (n: number) => known.get(n) ?? (template ? build(template.url, template.param, n) : undefined) +} + /** * Reads a Laravel paginator (`->paginate()` / `->simplePaginate()` as JSON) or an * API resource collection (`{ data, meta, links }`) into one shape (R16.4). @@ -82,7 +123,19 @@ export function normalizePagination(input: LaravelResourceCollection | LaravelPa const page = Number(meta.current_page) const lastPage = meta.last_page ?? (meta.total !== undefined ? Math.max(1, Math.ceil(meta.total / perPage)) : undefined) - const path = meta.path + const prevUrl = resourceLinks?.prev ?? meta.prev_page_url ?? null + const nextUrl = resourceLinks?.next ?? meta.next_page_url ?? null + + const known = new Map() + const add = (n: number | undefined, url: string | null | undefined) => { + if (n !== undefined && url && !known.has(n)) known.set(n, url) + } + if (Array.isArray(meta.links)) for (const link of meta.links) add(linkPage(link), link.url) + add(1, resourceLinks?.first ?? meta.first_page_url) + add(lastPage, resourceLinks?.last ?? meta.last_page_url) + add(page - 1, prevUrl) + add(page + 1, nextUrl) + return { page, perPage, @@ -90,15 +143,9 @@ export function normalizePagination(input: LaravelResourceCollection | LaravelPa lastPage, from: meta.from ?? undefined, to: meta.to ?? undefined, - prevUrl: resourceLinks?.prev ?? meta.prev_page_url ?? null, - nextUrl: resourceLinks?.next ?? meta.next_page_url ?? null, - pageUrl: path - ? (n: number) => { - const url = new URL(path, "http://localhost") - url.searchParams.set("page", String(n)) - return path.startsWith("http") ? url.toString() : `${url.pathname}${url.search}` - } - : undefined, + prevUrl, + nextUrl, + pageUrl: serverPageUrl(known, meta.path), } } @@ -209,10 +256,7 @@ export function Pagination({ const hrefFor = (target: number) => { if (target === page) return undefined - if (getPageHref) return getPageHref(target) - if (target === page - 1 && info?.prevUrl) return info.prevUrl - if (target === page + 1 && info?.nextUrl) return info.nextUrl - return undefined + return getPageHref?.(target) } const go = (target: number) => (event: React.MouseEvent) => { From 243964db7bee01505730435644ccd1ef34c7920b Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 18 Nov 2026 05:17:56 +0000 Subject: [PATCH 03/11] Only cancel page drops that carry files while a dropzone is mounted (#66, 5.3) Co-Authored-By: Claude Opus 5.5 --- .changeset/file-input-text-drop.md | 5 +++++ packages/onu/src/components/files/file-input.test.tsx | 2 ++ packages/onu/src/components/files/file-input.tsx | 1 + 3 files changed, 8 insertions(+) create mode 100644 .changeset/file-input-text-drop.md diff --git a/.changeset/file-input-text-drop.md b/.changeset/file-input-text-drop.md new file mode 100644 index 00000000..f2a2f396 --- /dev/null +++ b/.changeset/file-input-text-drop.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": patch +--- + +A mounted `FileInput` dropzone no longer cancels text dropped elsewhere on the page, such as into a textarea or the editor. diff --git a/packages/onu/src/components/files/file-input.test.tsx b/packages/onu/src/components/files/file-input.test.tsx index dbff3320..89093920 100644 --- a/packages/onu/src/components/files/file-input.test.tsx +++ b/packages/onu/src/components/files/file-input.test.tsx @@ -292,6 +292,8 @@ describe("FileInput appearance=dropzone", () => { expect(screen.getByLabelText("Browse file")).toBe(input(container)) // A file dropped next to the zone does not replace the page. expect(fireEvent.drop(document.body, { dataTransfer: filesData([dropped]) })).toBe(false) + // Text dropped elsewhere on the page (a textarea, the editor) is left alone. + expect(fireEvent.drop(document.body, { dataTransfer: { types: ["text/plain"], files: [] } })).toBe(true) }) it("accepts pasted files on the field and, optionally, the document", async () => { diff --git a/packages/onu/src/components/files/file-input.tsx b/packages/onu/src/components/files/file-input.tsx index c1d72ecd..331cbcd0 100644 --- a/packages/onu/src/components/files/file-input.tsx +++ b/packages/onu/src/components/files/file-input.tsx @@ -364,6 +364,7 @@ export function FileInput({ if (hasFiles(e.dataTransfer)) e.preventDefault() } const drop = (e: DragEvent) => { + if (!hasFiles(e.dataTransfer)) return const target = e.target as HTMLInputElement | null if (!(target?.tagName === "INPUT" && target.type === "file")) e.preventDefault() } From a6fd17b1144bf87dccc7b1f0f7a9fb3a9c041546 Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 18 Nov 2026 05:19:13 +0000 Subject: [PATCH 04/11] Drop results of aborted uploads even when the uploader ignores the signal (#66, 5.4) Co-Authored-By: Claude Opus 5.5 --- .changeset/upload-ignore-aborted.md | 5 ++++ .../src/components/files/file-input.test.tsx | 29 +++++++++++++++++++ .../onu/src/components/files/use-files.ts | 21 ++++++++++++-- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 .changeset/upload-ignore-aborted.md diff --git a/.changeset/upload-ignore-aborted.md b/.changeset/upload-ignore-aborted.md new file mode 100644 index 00000000..81a529f7 --- /dev/null +++ b/.changeset/upload-ignore-aborted.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": patch +--- + +A cancelled, removed or replaced upload no longer lands in the `FileInput` value when a custom `upload` ignores its abort signal, and Cancel marks the upload cancelled straight away. diff --git a/packages/onu/src/components/files/file-input.test.tsx b/packages/onu/src/components/files/file-input.test.tsx index 89093920..0de2be70 100644 --- a/packages/onu/src/components/files/file-input.test.tsx +++ b/packages/onu/src/components/files/file-input.test.tsx @@ -694,6 +694,35 @@ describe("FileInput uploads", () => { expect(screen.getByText("a.pdf removed")).toBeInTheDocument() }) + it("keeps cancelled and replaced uploads out of the value when the uploader ignores the signal", async () => { + const calls: { resolve: (v: unknown) => void }[] = [] + const upload = vi.fn(() => new Promise((resolve) => calls.push({ resolve }))) + const onUploaded = vi.fn() + const { container, unmount } = renderWithOnu( + , + ) + await user().upload(input(container), [file("a.pdf"), file("b.pdf")]) + await userEvent.click(screen.getByRole("button", { name: "Cancel upload of a.pdf" })) + expect(await screen.findByText("Upload of a.pdf cancelled")).toBeInTheDocument() + await userEvent.click(screen.getByRole("button", { name: "Cancel upload of b.pdf" })) + await userEvent.click(await screen.findByRole("button", { name: "Remove b.pdf" })) + await act(async () => calls[0]!.resolve({ id: 1 })) + await act(async () => calls[1]!.resolve({ id: 2 })) + expect(hiddenValues(container, "docs")).toEqual([]) + expect(onUploaded).not.toHaveBeenCalled() + expect(screen.getByText("Cancelled")).toBeInTheDocument() + unmount() + + // Single mode: the file picked last wins, whichever request finishes last. + calls.length = 0 + const single = renderWithOnu() + await user().upload(input(single.container), file("old.pdf")) + await user().upload(input(single.container), file("new.pdf")) + await act(async () => calls[1]!.resolve({ id: 20 })) + await act(async () => calls[0]!.resolve({ id: 10 })) + expect(hiddenValues(single.container, "slip")).toEqual(["20"]) + }) + it("shows Laravel errors and calls onError", async () => { const { upload, calls } = controllableUploader() const onError = vi.fn() diff --git a/packages/onu/src/components/files/use-files.ts b/packages/onu/src/components/files/use-files.ts index 79169170..4bfc5dbc 100644 --- a/packages/onu/src/components/files/use-files.ts +++ b/packages/onu/src/components/files/use-files.ts @@ -189,6 +189,8 @@ export function useUploadQueue(options: UseUploadQueueOptions) { onProgress: (progress) => update(id, { progress: Math.max(0, Math.min(100, progress)) }), }).then( (response) => { + // A custom uploader may ignore the signal: a cancelled, removed or replaced upload still resolves. + if (controller.signal.aborted) return controllers.current.delete(id) const patch = { status: "success", progress: 100, response } as const update(id, patch) @@ -196,8 +198,10 @@ export function useUploadQueue(options: UseUploadQueueOptions) { callbacks.current.onUploaded?.({ id, file, ...patch }) }, (error: unknown) => { + // Cancelling already marked it; a removed or replaced upload has left the list. + if (controller.signal.aborted) return controllers.current.delete(id) - if (isAbortError(error) || controller.signal.aborted) { + if (isAbortError(error)) { update(id, { status: "cancelled" }) setAnnouncement(t("file.cancelledFile", { name: file.name })) return @@ -229,7 +233,18 @@ export function useUploadQueue(options: UseUploadQueueOptions) { [start], ) - const cancel = React.useCallback((id: string) => controllers.current.get(id)?.abort(), []) + const cancel = React.useCallback( + (id: string) => { + const controller = controllers.current.get(id) + if (!controller) return + controllers.current.delete(id) + controller.abort() + update(id, { status: "cancelled" }) + const item = items.find((i) => i.id === id) + if (item) setAnnouncement(t("file.cancelledFile", { name: item.file.name })) + }, + [items, update, t], + ) const retry = React.useCallback( (id: string) => { @@ -241,11 +256,13 @@ export function useUploadQueue(options: UseUploadQueueOptions) { const remove = React.useCallback((id: string) => { controllers.current.get(id)?.abort() + controllers.current.delete(id) setItems((list) => list.filter((item) => item.id !== id)) }, []) const clear = React.useCallback(() => { for (const controller of controllers.current.values()) controller.abort() + controllers.current.clear() setItems([]) }, []) From 9194803fa66358527141df66314cf00c9bac0b6b Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 18 Nov 2026 05:20:16 +0000 Subject: [PATCH 05/11] Scope FilterPanel's count and Clear all to its own filters (#66, 5.5) Co-Authored-By: Claude Opus 5.5 --- .changeset/filter-panel-scope.md | 5 ++++ docs/listing-pages/filter-panel.md | 4 ++-- .../components/listing/filter-panel.test.tsx | 12 ++++++++++ .../src/components/listing/filter-panel.tsx | 23 ++++++++++++++----- 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 .changeset/filter-panel-scope.md diff --git a/.changeset/filter-panel-scope.md b/.changeset/filter-panel-scope.md new file mode 100644 index 00000000..a7e3946c --- /dev/null +++ b/.changeset/filter-panel-scope.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": patch +--- + +`FilterPanel`'s count badge and Clear all now cover only the filters in the panel, so tabs and `ListingPage` query filters are no longer counted or cleared by it. diff --git a/docs/listing-pages/filter-panel.md b/docs/listing-pages/filter-panel.md index 7ab1dd1e..7131c799 100644 --- a/docs/listing-pages/filter-panel.md +++ b/docs/listing-pages/filter-panel.md @@ -79,7 +79,7 @@ For a classic filter bar that you render yourself (a `GET` form above a server-r - Changes in the panel are a draft: the list doesn't change until **Apply**. - **Cancel**, Escape or clicking outside close the panel and throw the draft away. -- **Clear all** removes every filter straight away and closes the panel. +- **Clear all** removes every filter in the panel straight away and closes the panel. The button's count and Clear all cover only the panel's `filters`: tabs and `queryFilters` in the same `value` are left alone. - Each filter has its own **Clear** link. - Reopening the panel always shows the filters currently applied. @@ -102,7 +102,7 @@ Every definition also accepts `render` (replace the built-in control) and `forma | ----------------------- | ---------------------------------------------------------- | --------------- | -------------------------------------- | | `filters` | `FilterDefinition[]` | | Filters on offer | | `value` | `FilterValues` | | Applied filters | -| `onApply` | `(filters) => void` | | Apply (and `{}` on Clear all) | +| `onApply` | `(filters) => void` | | Apply, and Clear all (the panel's filters removed) | | `open` / `onOpenChange` | `boolean` / `(open) => void` | | Controlled open state | | `defaultOpen` | `boolean` | `false` | Initial open state when uncontrolled | | `sheet` | `boolean` | below 768px | Force the bottom sheet or the dropdown | diff --git a/packages/onu/src/components/listing/filter-panel.test.tsx b/packages/onu/src/components/listing/filter-panel.test.tsx index 5aee753e..0b23e3e3 100644 --- a/packages/onu/src/components/listing/filter-panel.test.tsx +++ b/packages/onu/src/components/listing/filter-panel.test.tsx @@ -159,6 +159,18 @@ describe("FilterPanel", () => { await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument()) }) + it("counts and clears only its own filters, keeping tabs and query filters it doesn't show", async () => { + renderWithOnu() + const button = screen.getByRole("button", { name: "Filters, 1 applied" }) + expect(within(button).getByText("1")).toBeInTheDocument() + const panel = await openPanel() + await userEvent.click(within(panel).getByRole("button", { name: "Clear all" })) + expect(applied()).toEqual({ tab: "archived", owner: "me" }) + expect(screen.getByRole("button", { name: "Filters" })).toBeInTheDocument() + await openPanel() + expect(screen.getByRole("button", { name: "Clear all" })).toBeDisabled() + }) + it("each filter has its own Clear link (§25.7)", async () => { renderWithOnu() const panel = await openPanel() diff --git a/packages/onu/src/components/listing/filter-panel.tsx b/packages/onu/src/components/listing/filter-panel.tsx index 47e9b3c2..da9924eb 100644 --- a/packages/onu/src/components/listing/filter-panel.tsx +++ b/packages/onu/src/components/listing/filter-panel.tsx @@ -27,7 +27,10 @@ export interface FilterPanelProps { filters: FilterDefinition[] /** The applied filters. */ value: FilterValues - /** Called with the new filters on Apply, and with `{}` on Clear all. */ + /** + * Called with the new filters on Apply, and on Clear all with this panel's filters removed. + * Values for keys the panel doesn't show (tabs, `queryFilters`) are passed through untouched. + */ onApply: (filters: FilterValues) => void /** Controlled open state. */ open?: boolean @@ -74,6 +77,13 @@ export interface FilterPanelProps { * the page, changes are a draft until Filter (or Enter), Reset clears the * form's filters, and Expand shows the fields past `collapsedCount`. */ +/** The values with this panel's filters removed, keeping filters it doesn't own (tabs, query filters). */ +function withoutFilters(value: FilterValues, filters: FilterDefinition[]) { + const next = { ...value } + for (const definition of filters) delete next[definition.key] + return cleanFilters(next) +} + export function FilterPanel(props: FilterPanelProps) { const { t } = useTranslation() const { announce, region } = useAnnouncer({ role: "status" }) @@ -180,10 +190,9 @@ function FilterQueryForm({ className="touch:min-h-11" onClick={() => { // Reset clears this form's fields and keeps any other filters. - const next = { ...draft } - for (const definition of filters) delete next[definition.key] + const next = withoutFilters(draft, filters) setDraft(next) - onApply(cleanFilters(next)) + onApply(next) }} > {t("listing.filterReset")} @@ -241,7 +250,9 @@ function FilterPopoverPanel({ if (open) setDraft(value) } - const count = Object.values(cleanFilters(value)).length + // Only this panel's filters: tabs and query filters on the page are not its to count or clear. + const applied = cleanFilters(value) + const count = filters.filter((definition) => definition.key in applied).length const format = new Intl.NumberFormat(locale.numberLocale) const apply = () => { @@ -249,7 +260,7 @@ function FilterPopoverPanel({ setOpen(false) } const clearAll = () => { - onApply({}) + onApply(withoutFilters(value, filters)) setOpen(false) } From a94b5679a9e759f956d285545bed74c675177d42 Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 18 Nov 2026 05:21:14 +0000 Subject: [PATCH 06/11] Label custom filter controls with a real label and pass labelId (#66, 5.6) Co-Authored-By: Claude Opus 5.5 --- .changeset/filter-render-label.md | 5 ++++ docs/listing-pages/filter-panel.md | 4 +-- .../components/listing/_filter-controls.tsx | 29 +++++++++++++++++++ .../components/listing/filter-panel.test.tsx | 26 +++++++++++++++++ .../src/components/listing/filter-panel.tsx | 21 ++++++++------ .../src/components/listing/listing-types.ts | 4 ++- 6 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 .changeset/filter-render-label.md diff --git a/.changeset/filter-render-label.md b/.changeset/filter-render-label.md new file mode 100644 index 00000000..c8ee4000 --- /dev/null +++ b/.changeset/filter-render-label.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": patch +--- + +A custom filter `render` control is now named by the filter's label: the label is a real `