diff --git a/blocks/related-posts/style.css b/blocks/related-posts/style.css index 34ce5d7..d177709 100644 --- a/blocks/related-posts/style.css +++ b/blocks/related-posts/style.css @@ -44,6 +44,10 @@ html[data-theme="light"] .chrnx-related-posts { min-width: 0; } +.chrnx-related-card:focus-within { + box-shadow: inset 0 0 0 3px var(--chrnx-related-focus-ring); +} + .chrnx-related-posts.is-layout-grid .chrnx-related-posts__items { display: grid; grid-template-columns: minmax(0, 1fr); diff --git a/tests/e2e/related-stories.spec.mjs b/tests/e2e/related-stories.spec.mjs index e5708dc..ef70ad0 100644 --- a/tests/e2e/related-stories.spec.mjs +++ b/tests/e2e/related-stories.spec.mjs @@ -401,6 +401,48 @@ for ( const theme of [ 'light', 'dark' ] ) { } } +for ( const theme of [ 'light', 'dark' ] ) { + test( `full-card keyboard focus remains visible inside clipped ${ theme } cards`, async ( { + page, + browserName, + } ) => { + await page.setViewportSize( { width: 1440, height: 900 } ); + await page.goto( '/long-title-night-writing-fixture/' ); + await page.evaluate( ( selectedTheme ) => { + window.localStorage.setItem( 'chrnx-theme', selectedTheme ); + }, theme ); + await page.reload(); + + const links = page.locator( '#related-stories-5-grid .chrnx-related-card__link' ); + const focusedLink = links.nth( 1 ); + await links.first().focus(); + await page.keyboard.press( tabShortcut( browserName ) ); + await expect( focusedLink ).toBeFocused(); + + const appearance = await focusedLink.evaluate( ( link ) => { + const card = link.closest( '.chrnx-related-card' ); + const cardStyle = window.getComputedStyle( card ); + const linkStyle = window.getComputedStyle( link ); + const colors = cardStyle.boxShadow.match( + /rgba?\([^)]+\)|color\(srgb\s+[\d.]+\s+[\d.]+\s+[\d.]+(?:\s*\/\s*[\d.]+)?\)/gi, + ); + return { + background: cardStyle.backgroundColor, + cardOverflow: cardStyle.overflow, + cardShadow: cardStyle.boxShadow, + linkShadow: linkStyle.boxShadow, + ring: colors?.at( -1 ) || null, + }; + } ); + + expect( appearance.cardOverflow ).toBe( 'hidden' ); + expect( appearance.linkShadow ).not.toBe( 'none' ); + expect( appearance.cardShadow ).toContain( 'inset' ); + expect( appearance.ring ).toBeTruthy(); + expect( contrast( appearance.ring, appearance.background ) ).toBeGreaterThanOrEqual( 3 ); + } ); +} + test( 'layout matrix rail hover stays visibly contained in its scrollport', async ( { page } ) => { await page.setViewportSize( { width: 900, height: 900 } ); await page.goto( '/long-title-night-writing-fixture/' );