From f28aed149c237e45befad83c0f826b93497220e3 Mon Sep 17 00:00:00 2001 From: Robert Andreas Kyllo Date: Fri, 20 Nov 2026 19:54:04 +0100 Subject: [PATCH 1/2] feat: #104 move album filters into a side panel --- client/src/App.test.tsx | 10 +++- client/src/components/FilterPanel.css | 35 ++++++++++-- client/src/components/FilterPanel.test.tsx | 28 +++++++-- client/src/components/FilterPanel.tsx | 59 +++++++++++++------ client/src/test/setup.ts | 9 +++ e2e/tests/filters.spec.ts | 66 ++++++++++++++++++++++ e2e/tests/search.spec.ts | 2 +- 7 files changed, 179 insertions(+), 30 deletions(-) create mode 100644 e2e/tests/filters.spec.ts diff --git a/client/src/App.test.tsx b/client/src/App.test.tsx index 2ad820c..e08bbc5 100644 --- a/client/src/App.test.tsx +++ b/client/src/App.test.tsx @@ -17,7 +17,12 @@ import type { function resultStatus() { return within( screen.getByRole('region', { name: /^(Search results|Browse albums)$/ }), - ).getByRole('status'); + ).getByText( + /^Showing |^Loading albums|^Searching albums|^Retrying search|^Search failed\./, + { + selector: '.results-summary', + }, + ); } const album: AlbumSummary = { @@ -259,8 +264,7 @@ describe('App search', () => { const user = userEvent.setup(); screen.getByRole('button', { name: 'Filters' }).focus(); await user.keyboard('{Enter}'); - await user.tab(); - expect(screen.getByRole('combobox', { name: 'Sort by' })).toHaveFocus(); + expect(screen.getByRole('button', { name: 'Close filters' })).toHaveFocus(); await user.tab(); expect(screen.getByRole('button', { name: 'Clear filters' })).toHaveFocus(); await user.tab(); diff --git a/client/src/components/FilterPanel.css b/client/src/components/FilterPanel.css index b8de2ff..059c7a0 100644 --- a/client/src/components/FilterPanel.css +++ b/client/src/components/FilterPanel.css @@ -10,6 +10,7 @@ padding-block: 0.875rem; } .filter-toggle, +.close-filters, .clear-filters { min-height: 2.75rem; background: var(--surface); @@ -27,8 +28,32 @@ background: var(--chip-bg); } .filter-options { - border-top: 1px solid var(--border); - padding: 0.875rem 0; + position: fixed; + inset: 0 0 0 auto; + box-sizing: border-box; + width: min(28rem, 100%); + height: 100dvh; + max-width: 100%; + max-height: 100dvh; + margin: 0; + padding: 1.25rem; + border: 0; + border-left: 1px solid var(--border); + background: var(--surface); + color: var(--text); + overflow-y: auto; + overscroll-behavior: contain; +} +.filter-options::backdrop { + background: rgb(0 0 0 / 45%); +} +.filter-panel-actions { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 0.75rem; + margin-bottom: 1.5rem; } .filter-panel-header { display: flex; @@ -38,7 +63,7 @@ gap: 0.75rem; margin-bottom: 0.75rem; } -.filter-panel-header h3 { +.filter-panel-header h2 { margin: 0; font-size: 1rem; } @@ -49,7 +74,7 @@ } .filter-groups { display: grid; - grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr)); + grid-template-columns: minmax(0, 1fr); align-items: start; gap: 1rem 1.5rem; } @@ -87,7 +112,7 @@ display: flex; align-items: center; gap: 0.375rem; - min-height: 2rem; + min-height: 2.75rem; min-width: 0; max-width: 100%; border: 1px solid var(--border-strong); diff --git a/client/src/components/FilterPanel.test.tsx b/client/src/components/FilterPanel.test.tsx index 8f95dc3..de47644 100644 --- a/client/src/components/FilterPanel.test.tsx +++ b/client/src/components/FilterPanel.test.tsx @@ -86,7 +86,7 @@ describe('FilterPanel', () => { expect(props.onClear).toHaveBeenCalledTimes(1); }); - it('toggles the options with Space and Enter while showing active filters', async () => { + it('opens with Space and closes with Enter while showing active filters', async () => { renderPanel({ genres: ['4'], decades: [1970], reviewed: true }, false); const button = screen.getByRole('button', { name: 'Filters (3)' }); expect(screen.queryByRole('checkbox')).not.toBeInTheDocument(); @@ -99,6 +99,8 @@ describe('FilterPanel', () => { button.focus(); await user.keyboard(' '); expect(button).toHaveAttribute('aria-expanded', 'true'); + expect(screen.getByRole('dialog', { name: 'Refine albums' })).toBeVisible(); + expect(screen.getByRole('button', { name: 'Close filters' })).toHaveFocus(); await user.keyboard('{Enter}'); expect(button).toHaveAttribute('aria-expanded', 'false'); }); @@ -107,7 +109,8 @@ describe('FilterPanel', () => { renderPanel({}, false); const button = screen.getByRole('button', { name: 'Filters' }); fireEvent.click(button); - fireEvent.keyDown(screen.getByRole('checkbox', { name: /Rock/ }), { key: 'Escape' }); + // The browser dispatches cancel when Escape is pressed in a modal dialog. + fireEvent(screen.getByRole('dialog'), new Event('cancel', { cancelable: true })); expect(button).toHaveAttribute('aria-expanded', 'false'); expect(button).toHaveFocus(); }); @@ -232,7 +235,7 @@ describe('FilterPanel', () => { expect( screen.queryByRole('checkbox', { name: 'Country 7 1 albums' }), ).not.toBeInTheDocument(); - expect(screen.getByRole('button', { name: 'Filters' })).toHaveFocus(); + expect(screen.getByRole('button', { name: 'Close filters' })).toHaveFocus(); }); it('removes each filter independently and returns focus to the Filters toggle', async () => { @@ -301,6 +304,7 @@ describe('FilterPanel', () => { await user.tab(); expect(screen.getByRole('button', { name: 'Filters' })).toHaveFocus(); await user.keyboard('{Enter}'); + expect(screen.getByRole('button', { name: 'Close filters' })).toHaveFocus(); await user.tab(); expect(screen.getByRole('button', { name: 'Clear filters' })).toHaveFocus(); for (const name of [ @@ -333,7 +337,7 @@ describe('FilterPanel', () => { await userEvent.setup().keyboard(' '); rerender(); expect(screen.queryByRole('checkbox', { name })).not.toBeInTheDocument(); - expect(screen.getByRole('button', { name: 'Filters' })).toHaveFocus(); + expect(screen.getByRole('button', { name: 'Close filters' })).toHaveFocus(); }, ); @@ -369,10 +373,24 @@ describe('FilterPanel', () => { await userEvent.setup().keyboard(' '); rerender(); expect(screen.queryByRole('checkbox', { name })).not.toBeInTheDocument(); - expect(screen.getByRole('button', { name: /^Filters/ })).toHaveFocus(); + expect(screen.getByRole('button', { name: 'Close filters' })).toHaveFocus(); }, ); + it('locks background scrolling while open and restores it on close and unmount', () => { + const previousOverflow = document.body.style.overflow; + document.body.style.overflow = 'auto'; + const { unmount } = renderPanel(); + expect(document.body.style.overflow).toBe('hidden'); + fireEvent.click(screen.getByRole('button', { name: 'Close filters' })); + expect(document.body.style.overflow).toBe('auto'); + fireEvent.click(screen.getByRole('button', { name: 'Filters' })); + expect(document.body.style.overflow).toBe('hidden'); + unmount(); + expect(document.body.style.overflow).toBe('auto'); + document.body.style.overflow = previousOverflow; + }); + it('has no axe violations', async () => { const { container } = renderPanel({ genres: ['4'] }); const results = await axe.run(container, { diff --git a/client/src/components/FilterPanel.tsx b/client/src/components/FilterPanel.tsx index bcbbbe9..58c33e7 100644 --- a/client/src/components/FilterPanel.tsx +++ b/client/src/components/FilterPanel.tsx @@ -38,7 +38,7 @@ function toggle(list: T[], value: T): T[] { * an empty page. A selected option always stays, so it can be unticked. * * The options open from a Filters button above the results, so the panel only - * takes space while it is in use. Escape closes it and returns focus to the + * opens as a modal side drawer. Escape closes it and returns focus to the * button. Toolbar children provide the result summary and sorting control. */ export default function FilterPanel(props: Props) { @@ -120,16 +120,22 @@ export default function FilterPanel(props: Props) { props.countries.includes(countryCode), ); const toggleRef = useRef(null); + const dialogRef = useRef(null); + const closeRef = useRef(null); useEffect(() => { if (!open) return; - const closeOnEscape = (event: KeyboardEvent) => { - if (event.key !== 'Escape') return; - setOpen(false); - toggleRef.current?.focus(); + const dialog = dialogRef.current; + const trigger = toggleRef.current; + const previousOverflow = document.body.style.overflow; + dialog?.showModal(); + document.body.style.overflow = 'hidden'; + closeRef.current?.focus(); + return () => { + dialog?.close(); + document.body.style.overflow = previousOverflow; + trigger?.focus(); }; - document.addEventListener('keydown', closeOnEscape); - return () => document.removeEventListener('keydown', closeOnEscape); }, [open]); return ( @@ -139,6 +145,7 @@ export default function FilterPanel(props: Props) { ref={toggleRef} type="button" className="filter-toggle" + aria-haspopup="dialog" aria-expanded={open} aria-controls="filter-options" onClick={() => setOpen(!open)} @@ -166,11 +173,31 @@ export default function FilterPanel(props: Props) { ))} )} - + ); } diff --git a/client/src/test/setup.ts b/client/src/test/setup.ts index 4f41d02..e2a0e9b 100644 --- a/client/src/test/setup.ts +++ b/client/src/test/setup.ts @@ -13,3 +13,12 @@ afterEach(() => { cleanup(); window.history.replaceState({}, '', '/'); }); + +// jsdom does not implement dialog's modal lifecycle. Native focus containment, +// Escape and background inertness are verified in the browser tests. +HTMLDialogElement.prototype.showModal = function () { + this.setAttribute('open', ''); +}; +HTMLDialogElement.prototype.close = function () { + this.removeAttribute('open'); +}; diff --git a/e2e/tests/filters.spec.ts b/e2e/tests/filters.spec.ts new file mode 100644 index 0000000..f8b89f7 --- /dev/null +++ b/e2e/tests/filters.spec.ts @@ -0,0 +1,66 @@ +import { expect, test } from '@playwright/test'; + +for (const viewport of [ + { name: 'desktop', width: 1440, height: 900 }, + { name: 'mobile', width: 390, height: 844 }, +]) { + test(`filter drawer supports keyboard use and URL state on ${viewport.name}`, async ({ + page, + }, testInfo) => { + await page.setViewportSize(viewport); + await page.goto('./?q=beatles&sort=TITLE_DESC'); + await expect(page.getByRole('status').filter({ hasText: 'Showing' })).toHaveText( + /Showing 2 of 2 /, + ); + + await page.getByRole('button', { name: 'Filters', exact: true }).focus(); + await page.keyboard.press('Enter'); + const drawer = page.getByRole('dialog', { name: 'Refine albums' }); + const close = drawer.getByRole('button', { name: 'Close filters' }); + await expect(drawer).toBeVisible(); + await expect(close).toBeFocused(); + + // Native modal behavior keeps keyboard focus and accessibility navigation + // inside the drawer, including when tabbing backwards from its first control. + await page.keyboard.press('Shift+Tab'); + await expect + .poll(() => drawer.evaluate((element) => element.contains(document.activeElement))) + .toBe(true); + await page.keyboard.press('Tab'); + await expect(close).toBeFocused(); + await expect(page.getByRole('combobox', { name: 'Sort by' })).toHaveCount(0); + + await drawer.getByRole('checkbox', { name: /1960s/ }).check(); + await expect(page).toHaveURL(/[?&]decades=1960/); + await expect(drawer.getByRole('status')).toHaveText('1 active filter'); + const bounds = await drawer.boundingBox(); + expect(bounds).not.toBeNull(); + expect(bounds!.x).toBeGreaterThanOrEqual(0); + expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(viewport.width + 1); + expect(bounds!.width).toBeLessThanOrEqual(448); + expect(await drawer.evaluate((el) => el.scrollWidth <= el.clientWidth)).toBe(true); + await page.screenshot({ path: testInfo.outputPath('filter-panel.png') }); + + await page.keyboard.press('Escape'); + await expect(drawer).not.toBeVisible(); + await expect(page.getByRole('button', { name: 'Filters (1)' })).toBeFocused(); + await expect(page.getByRole('list', { name: 'Active filters' })).toContainText( + '1960s', + ); + await expect(page.getByRole('combobox', { name: 'Sort by' })).toHaveValue( + 'TITLE_DESC', + ); + + await page.reload(); + await page.getByRole('button', { name: 'Filters (1)' }).click(); + await expect(drawer.getByRole('checkbox', { name: /1960s/ })).toBeChecked(); + await drawer.getByRole('button', { name: 'Clear filters' }).click(); + await expect(drawer.getByRole('status')).toHaveText('0 active filters'); + await close.click(); + await expect( + page.getByRole('button', { name: 'Filters', exact: true }), + ).toBeFocused(); + await expect(page).toHaveURL(/\?q=beatles&sort=TITLE_DESC$/); + await expect(page.getByRole('list', { name: 'Active filters' })).toHaveCount(0); + }); +} diff --git a/e2e/tests/search.spec.ts b/e2e/tests/search.spec.ts index 5d74157..d14152e 100644 --- a/e2e/tests/search.spec.ts +++ b/e2e/tests/search.spec.ts @@ -46,10 +46,10 @@ test('search, filter, sort, open an album and keep a review across a reload', as await page.getByRole('button', { name: 'Filters', exact: true }).click(); await page.getByRole('checkbox', { name: /1960s/ }).check(); await expect(page).toHaveURL(/[?&]decades=1960/); + await page.keyboard.press('Escape'); await expect( page.getByRole('button', { name: 'Filters (1)', exact: true }), ).toBeVisible(); - await page.keyboard.press('Escape'); // Sort: both directions, so the test cannot pass by accident on insertion order. const sort = page.getByRole('combobox', { name: 'Sort by' }); From e03773b5f4268326f8c934029a583826d1680539 Mon Sep 17 00:00:00 2001 From: Robert Andreas Kyllo Date: Mon, 23 Nov 2026 11:50:27 +0100 Subject: [PATCH 2/2] fix: #104 address filter drawer review feedback --- client/src/App.test.tsx | 2 +- client/src/components/FilterPanel.test.tsx | 17 +++++++ client/src/components/FilterPanel.tsx | 52 ++++++++++++++++++++-- docs/AI-USAGE.md | 1 + e2e/tests/filters.spec.ts | 10 ++++- 5 files changed, 77 insertions(+), 5 deletions(-) diff --git a/client/src/App.test.tsx b/client/src/App.test.tsx index e08bbc5..b379e72 100644 --- a/client/src/App.test.tsx +++ b/client/src/App.test.tsx @@ -18,7 +18,7 @@ function resultStatus() { return within( screen.getByRole('region', { name: /^(Search results|Browse albums)$/ }), ).getByText( - /^Showing |^Loading albums|^Searching albums|^Retrying search|^Search failed\./, + /^Showing |^Loading albums|^Searching albums|^Retrying search|^Search failed\.|^Retrying albums|^Could not load albums\.|^Loading more albums/, { selector: '.results-summary', }, diff --git a/client/src/components/FilterPanel.test.tsx b/client/src/components/FilterPanel.test.tsx index de47644..31dd83f 100644 --- a/client/src/components/FilterPanel.test.tsx +++ b/client/src/components/FilterPanel.test.tsx @@ -115,6 +115,23 @@ describe('FilterPanel', () => { expect(button).toHaveFocus(); }); + it('closes from the backdrop but stays open for clicks inside the drawer', async () => { + renderPanel({}, false); + const trigger = screen.getByRole('button', { name: 'Filters' }); + await userEvent.setup().click(trigger); + const dialog = screen.getByRole('dialog', { name: 'Refine albums' }); + vi.spyOn(dialog, 'getBoundingClientRect').mockReturnValue( + new DOMRect(800, 0, 400, 900), + ); + + fireEvent.click(dialog, { clientX: 900, clientY: 100 }); + expect(dialog).toBeVisible(); + + fireEvent.click(dialog, { clientX: 100, clientY: 100 }); + expect(dialog).not.toBeVisible(); + expect(trigger).toHaveFocus(); + }); + it('makes every active filter available as a removable chip', () => { renderPanel({ decades: [1950, 1960, 1970, 1980, 1990], diff --git a/client/src/components/FilterPanel.tsx b/client/src/components/FilterPanel.tsx index 58c33e7..ee6605d 100644 --- a/client/src/components/FilterPanel.tsx +++ b/client/src/components/FilterPanel.tsx @@ -37,9 +37,9 @@ function toggle(list: T[], value: T): T[] { * Options that would give zero results are hidden, so the panel never leads to * an empty page. A selected option always stays, so it can be unticked. * - * The options open from a Filters button above the results, so the panel only - * opens as a modal side drawer. Escape closes it and returns focus to the - * button. Toolbar children provide the result summary and sorting control. + * The options open from a Filters button above the results as a modal side + * drawer. Escape closes it and returns focus to the button. Toolbar children + * provide the result summary and sorting control. */ export default function FilterPanel(props: Props) { const genres = props.genreFacets.filter( @@ -138,6 +138,52 @@ export default function FilterPanel(props: Props) { }; }, [open]); + useEffect(() => { + const dialog = dialogRef.current; + if (!dialog) return; + + const closeOnBackdropClick = (event: MouseEvent) => { + if (event.target !== dialog) return; + const bounds = dialog.getBoundingClientRect(); + const clickIsInsideDrawer = + event.clientX >= bounds.left && + event.clientX <= bounds.right && + event.clientY >= bounds.top && + event.clientY <= bounds.bottom; + if (!clickIsInsideDrawer) setOpen(false); + }; + + const keepTabFocusInsideDialog = (event: KeyboardEvent) => { + if (event.key !== 'Tab') return; + const focusableElements = Array.from( + dialog.querySelectorAll( + 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])', + ), + ).filter( + (element) => + element.tabIndex >= 0 && + element.getAttribute('aria-hidden') !== 'true' && + !element.closest('[hidden]'), + ); + const first = focusableElements[0]; + const last = focusableElements.at(-1); + if (event.shiftKey && document.activeElement === first) { + event.preventDefault(); + last?.focus(); + } else if (!event.shiftKey && document.activeElement === last) { + event.preventDefault(); + first?.focus(); + } + }; + + dialog.addEventListener('click', closeOnBackdropClick); + dialog.addEventListener('keydown', keepTabFocusInsideDialog); + return () => { + dialog.removeEventListener('click', closeOnBackdropClick); + dialog.removeEventListener('keydown', keepTabFocusInsideDialog); + }; + }, []); + return (
diff --git a/docs/AI-USAGE.md b/docs/AI-USAGE.md index 5a9659f..397cc61 100644 --- a/docs/AI-USAGE.md +++ b/docs/AI-USAGE.md @@ -109,6 +109,7 @@ the part that matters most. | 2026-11-22 | evenkkl | Claude | #96, skip count and facet queries on Load more: Claude made the search aggregates lazy `AlbumConnection` field resolvers, added a `SearchAlbumsPage` query for Load more, kept page one's count and facets in the Apollo merge, and added server and client tests. Verified with lint, typecheck, the test suites and the PostgreSQL tests on PGlite. | | 2026-11-22 | erikhfj | Antigravity | #117, stabilized `ReviewForm.test.tsx`: traced the intermittent CI failure (run `88055`) to `findByRole('status')` resolving via `MutationObserver` before React's passive `useEffect` focused `statusRef`, and wrapped the status focus assertions in `waitFor`. Verified with 10 consecutive test runs plus `pnpm format:check && pnpm lint && pnpm typecheck && pnpm test`. | | 2026-11-22 | erikhfj | Antigravity | #107, documented the team's AI task delegation, verification, and review workflow in `docs/AI-USAGE.md`, reflecting actual practices across all four contributors and complementing #97's prompt-context section. Verified with `pnpm format:check && pnpm lint && pnpm typecheck && pnpm test`. | +| 2026-11-23 | robertky | Codex (ChatGPT) | #104 review follow-up: combined the side drawer with the merged country preview, added backdrop dismissal and a keyboard focus loop, corrected the results-status test matcher and component documentation, and expanded the Playwright filter journey. Verified with `pnpm format:check`, `pnpm lint`, `pnpm typecheck`, `pnpm test`, `pnpm build`, and `pnpm test:e2e` against an isolated seeded PostgreSQL database. | ## Task delegation and verification workflow diff --git a/e2e/tests/filters.spec.ts b/e2e/tests/filters.spec.ts index f8b89f7..cd6c68e 100644 --- a/e2e/tests/filters.spec.ts +++ b/e2e/tests/filters.spec.ts @@ -28,7 +28,6 @@ for (const viewport of [ .toBe(true); await page.keyboard.press('Tab'); await expect(close).toBeFocused(); - await expect(page.getByRole('combobox', { name: 'Sort by' })).toHaveCount(0); await drawer.getByRole('checkbox', { name: /1960s/ }).check(); await expect(page).toHaveURL(/[?&]decades=1960/); @@ -41,6 +40,15 @@ for (const viewport of [ expect(await drawer.evaluate((el) => el.scrollWidth <= el.clientWidth)).toBe(true); await page.screenshot({ path: testInfo.outputPath('filter-panel.png') }); + if (viewport.width > 448) { + await page.mouse.click(0, 0); + await expect(drawer).not.toBeVisible(); + const filterButton = page.getByRole('button', { name: 'Filters (1)' }); + await expect(filterButton).toBeFocused(); + await filterButton.click(); + await expect(drawer).toBeVisible(); + } + await page.keyboard.press('Escape'); await expect(drawer).not.toBeVisible(); await expect(page.getByRole('button', { name: 'Filters (1)' })).toBeFocused();