fix: polish Related Stories interactions

This commit is contained in:
chrnx committed 2026-08-12 21:23:41 -05:00
1 parent 9058d5592f
commit d8ad3d388f
3 files changed
+145 -14

No files matched your search

+25
View File
@@ -108,6 +108,23 @@ html[data-theme="light"] .chrnx-related-posts {
box-shadow: 0 0 0 3px var(--chrnx-related-focus-ring);
}
.chrnx-related-posts__controls button:not(:disabled):hover {
border-color: var(--chrnx-related-focus-ring);
background: color-mix(in srgb, var(--chrnx-related-control-background) 88%, var(--chrnx-related-control-text));
}
.chrnx-related-posts__controls button:not(:disabled):active {
background: color-mix(in srgb, var(--chrnx-related-control-background) 74%, var(--chrnx-related-control-text));
}
@media (hover: hover) {
.chrnx-related-posts.is-layout-carousel .chrnx-related-card:hover {
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--chrnx-green) 62%, transparent);
transform: none;
}
}
@media (max-width: 900px) {
.chrnx-related-posts.is-layout-adaptive .chrnx-related-posts__items {
@@ -123,6 +140,14 @@ html[data-theme="light"] .chrnx-related-posts {
flex: 0 0 calc(100% - clamp(3rem, 12vw, 7rem));
scroll-snap-align: start;
}
@media (hover: hover) {
.chrnx-related-posts.is-layout-adaptive .chrnx-related-card:hover {
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--chrnx-green) 62%, transparent);
transform: none;
}
}
}
@media (min-width: 901px) {
+118 -13
View File
@@ -146,13 +146,19 @@ const layoutCases = [
{ limit: 3, layout: 'carousel' },
{ limit: 5, layout: 'carousel' },
];
const unbrokenRelatedTitle =
'DifficultyIsAConversationNotAGateEvenWhenOneUnbrokenEditorialTitleKeepsGoingWithoutAnyNaturalPlaceForTheCardToWrapSafely';
function colorChannels( color ) {
const channels = color.match( /rgba?\(\s*([\d.]+)[, ]+\s*([\d.]+)[, ]+\s*([\d.]+)/i );
if ( ! channels ) {
throw new Error( `Expected an RGB color, received ${ color }` );
if ( channels ) {
return channels.slice( 1, 4 ).map( Number );
}
return channels.slice( 1, 4 ).map( Number );
const srgb = color.match( /color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/i );
if ( srgb ) {
return srgb.slice( 1, 4 ).map( ( channel ) => Number( channel ) * 255 );
}
throw new Error( `Expected an RGB color, received ${ color }` );
}
function luminance( color ) {
@@ -317,16 +323,49 @@ for ( const theme of [ 'light', 'dark' ] ) {
await page.evaluate( () => {
document.documentElement.style.fontSize = '200%';
} );
const textIntegrity = await page
.locator( '[id^="related-stories-"] .chrnx-related-card__content' )
.evaluateAll( ( elements ) =>
elements.every(
( element ) =>
element.scrollWidth <= element.clientWidth + 1 &&
element.scrollHeight <= element.clientHeight + 1,
),
);
expect( textIntegrity ).toBe( true );
const longRelatedLink = page.locator(
'#related-stories-5-grid .chrnx-related-card__link[href$="/difficulty-is-a-conversation-not-a-gate/"]',
);
await expect( longRelatedLink ).toContainText( unbrokenRelatedTitle );
const textIntegrity = await longRelatedLink.evaluate( ( link ) => {
const card = link.closest( '.chrnx-related-card' );
const content = link.querySelector( '.chrnx-related-card__content' );
const title = link.querySelector( '.chrnx-related-card__title' );
const section = link.closest( '.chrnx-related-posts' );
const contains = ( parent, child ) => {
const parentRect = parent.getBoundingClientRect();
const childRect = child.getBoundingClientRect();
return (
childRect.left >= parentRect.left - 1 &&
childRect.right <= parentRect.right + 1 &&
childRect.top >= parentRect.top - 1 &&
childRect.bottom <= parentRect.bottom + 1
);
};
const unclipped = ( element ) =>
element.scrollWidth <= element.clientWidth + 1 &&
element.scrollHeight <= element.clientHeight + 1;
const titleStyle = window.getComputedStyle( title );
const titleRange = document.createRange();
titleRange.selectNodeContents( title );
return {
card: unclipped( card ) && contains( section, card ),
link: unclipped( link ) && contains( card, link ),
content: unclipped( content ) && contains( link, content ),
title:
! [ 'hidden', 'clip' ].includes( titleStyle.overflow ) &&
contains( content, title ) &&
contains( content, {
getBoundingClientRect: () => titleRange.getBoundingClientRect(),
} ),
};
} );
expect( textIntegrity ).toEqual( {
card: true,
link: true,
content: true,
title: true,
} );
expect(
await page.evaluate(
() => document.documentElement.scrollWidth <= document.documentElement.clientWidth,
@@ -335,3 +374,69 @@ for ( const theme of [ 'light', 'dark' ] ) {
} );
}
}
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/' );
const track = page.locator( '#related-stories-5-carousel [data-chrnx-related-track]' );
const card = track.locator( '.chrnx-related-card' ).first();
const baselineBorder = await card.evaluate(
( element ) => window.getComputedStyle( element ).borderColor,
);
await card.hover();
await expect
.poll( () => card.evaluate( ( element ) => window.getComputedStyle( element ).transform ) )
.toBe( 'none' );
const hover = await card.evaluate( ( element ) => {
const cardRect = element.getBoundingClientRect();
const trackRect = element.parentElement.getBoundingClientRect();
const style = window.getComputedStyle( element );
return {
border: style.borderColor,
shadow: style.boxShadow,
contained: cardRect.top >= trackRect.top && cardRect.bottom <= trackRect.bottom,
};
} );
expect( hover.contained ).toBe( true );
expect( hover.border ).not.toBe( baselineBorder );
expect( hover.shadow ).toContain( 'inset' );
} );
for ( const theme of [ 'light', 'dark' ] ) {
test( `layout matrix ${ theme } controls have distinct hover and active responses`, async ( {
page,
} ) => {
await page.setViewportSize( { width: 375, 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 button = page
.locator( '#related-stories-5-carousel .chrnx-related-posts__controls button:not(:disabled)' )
.first();
const readStyle = () =>
button.evaluate( ( element ) => {
const style = window.getComputedStyle( element );
return {
background: style.backgroundColor,
border: style.borderColor,
color: style.color,
};
} );
const baseline = await readStyle();
await button.hover();
const hovered = await readStyle();
expect( hovered.background ).not.toBe( baseline.background );
expect( hovered.border ).not.toBe( baseline.border );
expect( contrast( hovered.color, hovered.background ) ).toBeGreaterThanOrEqual( 4.5 );
await page.mouse.down();
const active = await readStyle();
expect( active.background ).not.toBe( hovered.background );
expect( contrast( active.color, active.background ) ).toBeGreaterThanOrEqual( 4.5 );
await page.mouse.up();
} );
}
+2 -1
View File
@@ -93,7 +93,8 @@
},
{
"fixtureKey": "post-gaming-accessibility",
"title": "Difficulty is a conversation, not a gate",
"slug": "difficulty-is-a-conversation-not-a-gate",
"title": "DifficultyIsAConversationNotAGateEvenWhenOneUnbrokenEditorialTitleKeepsGoingWithoutAnyNaturalPlaceForTheCardToWrapSafely",
"excerpt": "A note about challenge, access, and respecting different ways of reading a game.",
"content": "<!-- wp:paragraph --><p>Accessibility does not remove authorship. It gives more players a route into it.</p><!-- /wp:paragraph -->",
"topic": "gaming",