diff --git a/e2e/home.spec.ts b/e2e/home.spec.ts index 23b440fc..6a5928ae 100644 --- a/e2e/home.spec.ts +++ b/e2e/home.spec.ts @@ -7,4 +7,17 @@ test.describe('Home page', () => { const cards = await page.getByTestId(TEST_IDS.homepageCard.useCaseTitle); expect(await cards.count()).toBeGreaterThan(5); }); + + test('Entire cards should be clickable, clicking on the description or image should take you to the use case', async ({ + page, + }) => { + await page.goto('/'); + + await page.getByTestId(TEST_IDS.homepageCard.useCaseDescription).first().click({ force: true }); + await expect(page).toHaveURL('/playground'); + await page.goBack(); + + await page.getByTestId(TEST_IDS.homepageCard.useCaseIcon).first().click({ force: true }); + await expect(page).toHaveURL('/playground'); + }); }); diff --git a/src/client/testIDs.ts b/src/client/testIDs.ts index 2c786b64..f84f1929 100644 --- a/src/client/testIDs.ts +++ b/src/client/testIDs.ts @@ -18,6 +18,8 @@ export const TEST_IDS = { }, homepageCard: { useCaseTitle: 'useCaseTitle', + useCaseDescription: 'useCaseDescription', + useCaseIcon: 'useCaseIcon', }, loanRisk: { monthlyInstallmentValue: 'monthlyInstallmentValue', diff --git a/src/pages/index.module.scss b/src/pages/index.module.scss index 62dbf9df..837aebac 100644 --- a/src/pages/index.module.scss +++ b/src/pages/index.module.scss @@ -67,6 +67,8 @@ overflow: hidden; color: unset; cursor: pointer; + // We need this for the useCaseTitle pseudo element below + position: relative; @include shadowMedium(); @include transition((box-shadow, border)); @@ -93,6 +95,22 @@ line-height: 130%; margin-bottom: rem(8px); display: block; + + /** + * We need to make the whole card clickable. + * But wrapping the whole card in a element is bad for screen readers/accessibility. + * And using an `onClick` event on the card confuses Google Tag Manager triggers, it registers `click` instead of `linkClick`. + * So this is the best solution: https://kittygiraudel.com/2022/04/02/accessible-cards/ + */ + &::before { + // Use a pseudo-element to expand the hitbox of the link over the whole card. + content: ''; /* 1 */ + // Expand the hitbox over the whole card. + position: absolute; /* 2 */ + inset: 0; /* 2 */ + // Place the pseudo-element on top of the whole card. + z-index: 1; /* 3 */ + } } .useCaseDescription { diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 5421d73a..5c3b25c2 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -8,10 +8,8 @@ import Image from 'next/image'; import { TEST_IDS } from '../client/testIDs'; import { Fragment } from 'react'; import { SEO } from '../client/components/common/seo'; -import { useRouter } from 'next/router'; export default function Index() { - const router = useRouter(); return ( <>
{HOMEPAGE_CARDS.map((card) => ( -
router.push(card.url)}> +
- + {card.title} -
+
{card.descriptionHomepage?.map((line, i) => {line})}