From df76cbb6345f8caf79a14be15185e658ed557019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20=C3=98rjavik?= Date: Mon, 16 Nov 2026 13:54:02 +0100 Subject: [PATCH 1/2] fix(recipe): open the recipe when its card image is clicked Only the title link opened a recipe; clicking the image did nothing. Wrap the image in a link to the same page that is hidden from assistive technology and the tab order, so keyboard and screen-reader users still get a single link per card. Both links keep the browse state for Back. Closes #82 --- .../recipe/RecipeCard/RecipeCard.css | 8 ++++ .../recipe/RecipeCard/RecipeCard.tsx | 47 +++++++++++++------ .../recipe/__tests__/RecipeCard.test.tsx | 36 ++++++++++++++ 3 files changed, 76 insertions(+), 15 deletions(-) diff --git a/apps/web/src/components/recipe/RecipeCard/RecipeCard.css b/apps/web/src/components/recipe/RecipeCard/RecipeCard.css index 5806c0c..720ad36 100644 --- a/apps/web/src/components/recipe/RecipeCard/RecipeCard.css +++ b/apps/web/src/components/recipe/RecipeCard/RecipeCard.css @@ -55,6 +55,14 @@ background-color: var(--color-surface-muted); } + /* Fills the media area so the whole image is clickable. */ + .recipe-card__media-link { + display: block; + + width: 100%; + height: 100%; + } + .recipe-card__image { display: block; diff --git a/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx b/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx index 3c7b609..d36cd89 100644 --- a/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx +++ b/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx @@ -119,6 +119,11 @@ export default function RecipeCard({ const recipePath = `/recipes/${encodeURIComponent(recipeId)}`; + // Lets the detail page return to the exact Explore/Cookbook URL. + const recipeLinkState = { + from: `${location.pathname}${location.search}${location.hash}`, + }; + const usesBuiltInSaveAction = action == null && Boolean(onSaveChange); const visibleTags = tags.slice(0, MAX_VISIBLE_TAGS); @@ -183,18 +188,32 @@ export default function RecipeCard({ <>
- {imageSrc + {/* + * The image is a pointer/touch shortcut to the same page as the + * title link. It is removed from the tab order and hidden from + * assistive technology, so keyboard and screen-reader users still + * meet exactly one link per card (the title). + */} + + {imageSrc +
@@ -203,9 +222,7 @@ export default function RecipeCard({ {title} diff --git a/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx b/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx index ac78a8b..0c3b6a0 100644 --- a/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx +++ b/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx @@ -87,6 +87,42 @@ describe('RecipeCard', () => { ); }); + it('opens the recipe when the image is clicked, keeping browse state', async () => { + const user = userEvent.setup(); + + const { container } = render( + + + } /> + + } /> + + , + ); + + const image = container.querySelector('.recipe-card__image'); + expect(image).not.toBeNull(); + + await user.click(image!); + + expect(screen.getByTestId('recipe-location-state').textContent).toBe( + JSON.stringify({ from: '/?q=pasta&page=2' }), + ); + }); + + it('exposes only the title as a recipe link to keyboard and screen-reader users', () => { + const { container } = renderRecipeCard(baseProps); + + // The image link is hidden from the accessibility tree... + expect(screen.getAllByRole('link')).toHaveLength(1); + + // ...and from the tab order, but points to the same recipe. + const imageLink = container.querySelector('.recipe-card__media-link'); + expect(imageLink?.getAttribute('href')).toBe('/recipes/carbonara'); + expect(imageLink?.getAttribute('tabindex')).toBe('-1'); + expect(imageLink?.getAttribute('aria-hidden')).toBe('true'); + }); + it('renders structured cooking time and servings metadata', () => { renderRecipeCard(baseProps); From 6c77d83fad929dabd8fb3fbf70ebe32deef85dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20=C3=98rjavik?= Date: Mon, 16 Nov 2026 19:00:14 +0100 Subject: [PATCH 2/2] test(recipe): cover card image clicks instead of adding a second link Review on #90 was right: the title link's ::after overlay already covers the whole card, so clicking the image already opened the recipe (checked in a real browser). The extra aria-hidden image link was redundant and hid the image alt text from screen readers. Restore RecipeCard as before and add a browser test that clicks the image centre, since jsdom cannot hit-test the CSS overlay. Closes #82 --- .../recipe/RecipeCard/RecipeCard.css | 8 ---- .../recipe/RecipeCard/RecipeCard.tsx | 47 ++++++------------- .../recipe/__tests__/RecipeCard.test.tsx | 36 -------------- e2e/smoke.spec.ts | 16 +++++++ 4 files changed, 31 insertions(+), 76 deletions(-) diff --git a/apps/web/src/components/recipe/RecipeCard/RecipeCard.css b/apps/web/src/components/recipe/RecipeCard/RecipeCard.css index 720ad36..5806c0c 100644 --- a/apps/web/src/components/recipe/RecipeCard/RecipeCard.css +++ b/apps/web/src/components/recipe/RecipeCard/RecipeCard.css @@ -55,14 +55,6 @@ background-color: var(--color-surface-muted); } - /* Fills the media area so the whole image is clickable. */ - .recipe-card__media-link { - display: block; - - width: 100%; - height: 100%; - } - .recipe-card__image { display: block; diff --git a/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx b/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx index d36cd89..3c7b609 100644 --- a/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx +++ b/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx @@ -119,11 +119,6 @@ export default function RecipeCard({ const recipePath = `/recipes/${encodeURIComponent(recipeId)}`; - // Lets the detail page return to the exact Explore/Cookbook URL. - const recipeLinkState = { - from: `${location.pathname}${location.search}${location.hash}`, - }; - const usesBuiltInSaveAction = action == null && Boolean(onSaveChange); const visibleTags = tags.slice(0, MAX_VISIBLE_TAGS); @@ -188,32 +183,18 @@ export default function RecipeCard({ <>
- {/* - * The image is a pointer/touch shortcut to the same page as the - * title link. It is removed from the tab order and hidden from - * assistive technology, so keyboard and screen-reader users still - * meet exactly one link per card (the title). - */} - - {imageSrc - + {imageSrc
@@ -222,7 +203,9 @@ export default function RecipeCard({ {title} diff --git a/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx b/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx index 0c3b6a0..ac78a8b 100644 --- a/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx +++ b/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx @@ -87,42 +87,6 @@ describe('RecipeCard', () => { ); }); - it('opens the recipe when the image is clicked, keeping browse state', async () => { - const user = userEvent.setup(); - - const { container } = render( - - - } /> - - } /> - - , - ); - - const image = container.querySelector('.recipe-card__image'); - expect(image).not.toBeNull(); - - await user.click(image!); - - expect(screen.getByTestId('recipe-location-state').textContent).toBe( - JSON.stringify({ from: '/?q=pasta&page=2' }), - ); - }); - - it('exposes only the title as a recipe link to keyboard and screen-reader users', () => { - const { container } = renderRecipeCard(baseProps); - - // The image link is hidden from the accessibility tree... - expect(screen.getAllByRole('link')).toHaveLength(1); - - // ...and from the tab order, but points to the same recipe. - const imageLink = container.querySelector('.recipe-card__media-link'); - expect(imageLink?.getAttribute('href')).toBe('/recipes/carbonara'); - expect(imageLink?.getAttribute('tabindex')).toBe('-1'); - expect(imageLink?.getAttribute('aria-hidden')).toBe('true'); - }); - it('renders structured cooking time and servings metadata', () => { renderRecipeCard(baseProps); diff --git a/e2e/smoke.spec.ts b/e2e/smoke.spec.ts index 6b2ba23..cd60a87 100644 --- a/e2e/smoke.spec.ts +++ b/e2e/smoke.spec.ts @@ -248,6 +248,22 @@ test('icons stay within their controls on desktop and mobile', async ({ } }); +test('clicking anywhere on a recipe card, including its image, opens the recipe', async ({ + page, +}) => { + // The title link's ::after overlay (RecipeCard.css) covers the whole card. + // jsdom cannot hit-test CSS, so this is checked in a real browser. + await page.goto('.'); + const image = page.locator('.recipe-card__image').first(); + await expect(image).toBeVisible(); + const box = (await image.boundingBox())!; + await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2); + await expect(page).toHaveURL(/recipes\/11111111-1111-4111-8111-111111111111/); + await expect( + page.getByRole('heading', { name: 'Creamy salmon pasta' }), + ).toBeVisible(); +}); + test('renders each core route through the shared shell', async ({ page }) => { for (const [path, title] of coreRoutes) { await page.goto(path === '/' ? '.' : path.slice(1));