Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions client/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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\.|^Retrying albums|^Could not load albums\.|^Loading more albums/,
{
selector: '.results-summary',
},
);
}

const album: AlbumSummary = {
Expand Down Expand Up @@ -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();
Expand Down
35 changes: 30 additions & 5 deletions client/src/components/FilterPanel.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
padding-block: 0.875rem;
}
.filter-toggle,
.close-filters,
.clear-filters {
min-height: 2.75rem;
background: var(--surface);
Expand All @@ -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;
Expand All @@ -38,7 +63,7 @@
gap: 0.75rem;
margin-bottom: 0.75rem;
}
.filter-panel-header h3 {
.filter-panel-header h2 {
margin: 0;
font-size: 1rem;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
45 changes: 40 additions & 5 deletions client/src/components/FilterPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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');
});
Expand All @@ -107,11 +109,29 @@ 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();
});

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],
Expand Down Expand Up @@ -232,7 +252,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 () => {
Expand Down Expand Up @@ -301,6 +321,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 [
Expand Down Expand Up @@ -333,7 +354,7 @@ describe('FilterPanel', () => {
await userEvent.setup().keyboard(' ');
rerender(<FilterPanel {...props} genres={[]} />);
expect(screen.queryByRole('checkbox', { name })).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Filters' })).toHaveFocus();
expect(screen.getByRole('button', { name: 'Close filters' })).toHaveFocus();
},
);

Expand Down Expand Up @@ -369,10 +390,24 @@ describe('FilterPanel', () => {
await userEvent.setup().keyboard(' ');
rerender(<FilterPanel {...props} {...cleared} />);
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, {
Expand Down
109 changes: 91 additions & 18 deletions client/src/components/FilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function toggle<T>(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
* takes space while it is in use. 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(
Expand Down Expand Up @@ -120,25 +120,78 @@ export default function FilterPanel(props: Props) {
props.countries.includes(countryCode),
);
const toggleRef = useRef<HTMLButtonElement>(null);
const dialogRef = useRef<HTMLDialogElement>(null);
const closeRef = useRef<HTMLButtonElement>(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]);

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<HTMLElement>(
'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 (
<div className="filter-panel">
<div className="filter-toolbar">
<button
ref={toggleRef}
type="button"
className="filter-toggle"
aria-haspopup="dialog"
aria-expanded={open}
aria-controls="filter-options"
onClick={() => setOpen(!open)}
Expand Down Expand Up @@ -166,11 +219,31 @@ export default function FilterPanel(props: Props) {
))}
</ul>
)}
<div id="filter-options" className="filter-options" hidden={!open}>
<dialog
ref={dialogRef}
id="filter-options"
className="filter-options"
aria-labelledby="filter-panel-title"
onCancel={(event) => {
event.preventDefault();
setOpen(false);
}}
>
<div className="filter-panel-header">
<div>
<h3>Refine albums</h3>
</div>
<h2 id="filter-panel-title">Refine albums</h2>
<button
ref={closeRef}
type="button"
className="close-filters"
onClick={() => setOpen(false)}
>
Close filters
</button>
</div>
<div className="filter-panel-actions">
<p className="filter-panel-message" role="status" aria-live="polite">
{activeCount === 1 ? '1 active filter' : `${activeCount} active filters`}
</p>
<button
type="button"
className="clear-filters"
Expand Down Expand Up @@ -202,7 +275,7 @@ export default function FilterPanel(props: Props) {
(count === 0 ||
(!showAllGenres && index >= GENRE_PREVIEW_COUNT))
) {
toggleRef.current?.focus();
closeRef.current?.focus();
}
props.onGenresChange(toggle(props.genres, genre.id));
}}
Expand Down Expand Up @@ -241,7 +314,7 @@ export default function FilterPanel(props: Props) {
!event.currentTarget.checked &&
props.reviewedCount === 0
)
toggleRef.current?.focus();
closeRef.current?.focus();
props.onReviewedChange(event.target.checked);
}}
/>
Expand Down Expand Up @@ -271,7 +344,7 @@ export default function FilterPanel(props: Props) {
(count === 0 ||
(!showAllCountries && index >= COUNTRY_PREVIEW_COUNT))
)
toggleRef.current?.focus();
closeRef.current?.focus();
props.onCountriesChange(
toggle(props.countries, countryCode),
);
Expand Down Expand Up @@ -315,7 +388,7 @@ export default function FilterPanel(props: Props) {
!event.currentTarget.checked &&
count === 0
)
toggleRef.current?.focus();
closeRef.current?.focus();
props.onDecadesChange(toggle(props.decades, decade));
}}
/>
Expand All @@ -334,7 +407,7 @@ export default function FilterPanel(props: Props) {
</p>
)}
</div>
</div>
</dialog>
</div>
);
}
9 changes: 9 additions & 0 deletions client/src/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
1 change: 1 addition & 0 deletions docs/AI-USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading