fix: preserve Related Stories focus on hover
This commit is contained in:
2 files changed
+57
-3
No files matched your search
@@ -44,7 +44,7 @@ html[data-theme="light"] .chrnx-related-posts {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.chrnx-related-card:focus-within {
|
||||
.chrnx-related-posts .chrnx-related-card:focus-within {
|
||||
box-shadow: inset 0 0 0 3px var(--chrnx-related-focus-ring);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ html[data-theme="light"] .chrnx-related-posts {
|
||||
|
||||
@media (hover: hover) {
|
||||
|
||||
.chrnx-related-posts.is-layout-carousel .chrnx-related-card:hover {
|
||||
.chrnx-related-posts.is-layout-carousel .chrnx-related-card:hover:not(:focus-within) {
|
||||
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--chrnx-green) 62%, transparent);
|
||||
transform: none;
|
||||
}
|
||||
@@ -147,7 +147,7 @@ html[data-theme="light"] .chrnx-related-posts {
|
||||
|
||||
@media (hover: hover) {
|
||||
|
||||
.chrnx-related-posts.is-layout-adaptive .chrnx-related-card:hover {
|
||||
.chrnx-related-posts.is-layout-adaptive .chrnx-related-card:hover:not(:focus-within) {
|
||||
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--chrnx-green) 62%, transparent);
|
||||
transform: none;
|
||||
}
|
||||
|
||||
@@ -443,6 +443,60 @@ for ( const theme of [ 'light', 'dark' ] ) {
|
||||
} );
|
||||
}
|
||||
|
||||
for ( const theme of [ 'light', 'dark' ] ) {
|
||||
for ( const railCase of [
|
||||
{ name: 'adaptive mobile', anchor: 'related-stories-5-adaptive', width: 900 },
|
||||
{ name: 'carousel desktop', anchor: 'related-stories-5-carousel', width: 1440 },
|
||||
] ) {
|
||||
test( `${ railCase.name } ${ theme } card keeps its keyboard focus ring while hovered`, async ( {
|
||||
page,
|
||||
browserName,
|
||||
} ) => {
|
||||
await page.setViewportSize( { width: railCase.width, 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 section = page.locator( `#${ railCase.anchor } .chrnx-related-posts` );
|
||||
const track = section.locator( '[data-chrnx-related-track]' );
|
||||
const link = section.locator( '.chrnx-related-card__link' ).first();
|
||||
await track.focus();
|
||||
await page.keyboard.press( tabShortcut( browserName ) );
|
||||
await expect( link ).toBeFocused();
|
||||
await link.hover();
|
||||
await expect( link ).toBeFocused();
|
||||
|
||||
const appearance = await link.evaluate( ( focusedLink ) => {
|
||||
const card = focusedLink.closest( '.chrnx-related-card' );
|
||||
const style = window.getComputedStyle( card );
|
||||
const token = style.getPropertyValue( '--chrnx-related-focus-ring' ).trim();
|
||||
const probe = document.createElement( 'span' );
|
||||
probe.style.color = token;
|
||||
card.append( probe );
|
||||
const normalizedToken = window.getComputedStyle( probe ).color;
|
||||
probe.remove();
|
||||
const colors = style.boxShadow.match(
|
||||
/rgba?\([^)]+\)|color\(srgb\s+[\d.]+\s+[\d.]+\s+[\d.]+(?:\s*\/\s*[\d.]+)?\)/gi,
|
||||
);
|
||||
return {
|
||||
background: style.backgroundColor,
|
||||
ring: colors?.at( -1 ) || null,
|
||||
shadow: style.boxShadow,
|
||||
token: normalizedToken,
|
||||
};
|
||||
} );
|
||||
|
||||
expect( appearance.shadow ).toContain( 'inset' );
|
||||
expect( appearance.shadow ).toMatch( /0px 0px 0px 3px/ );
|
||||
expect( appearance.ring ).toBeTruthy();
|
||||
expect( colorChannels( appearance.ring ) ).toEqual( colorChannels( appearance.token ) );
|
||||
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/' );
|
||||
|
||||
Reference in new issue
Block a user