fix: restore Related Stories resize focus

This commit is contained in:
chrnx committed 2026-08-12 22:59:35 -05:00
1 parent 12259f4837
commit 5957bd566b
5 files changed
+24 -37

No files matched your search

+9 -5
View File
@@ -602,9 +602,8 @@ for ( const buttonName of [ 'Previous stories', 'Next stories' ] ) {
await page.setViewportSize( { width: 900, height: 900 } );
await page.goto( '/long-title-night-writing-fixture/' );
const section = page.locator( '#related-stories-3-adaptive .chrnx-related-posts' );
const heading = section.getByRole( 'heading', {
name: 'Related stories',
} );
const firstCardLink = section.locator( '.chrnx-related-card__link' ).first();
const controls = section.locator( '.chrnx-related-posts__controls' );
if ( buttonName === 'Previous stories' ) {
await section.getByRole( 'button', { name: 'Next stories' } ).click();
await expect( section.getByRole( 'button', { name: 'Previous stories' } ) ).toBeEnabled();
@@ -613,8 +612,13 @@ for ( const buttonName of [ 'Previous stories', 'Next stories' ] ) {
await button.focus();
await expect( button ).toBeFocused();
await page.setViewportSize( { width: 901, height: 900 } );
await expect( heading ).toBeFocused();
await expect( section.locator( '.chrnx-related-posts__controls' ) ).toBeHidden();
await expect( firstCardLink ).toBeFocused();
await expect( controls ).toBeHidden();
expect(
await controls.evaluate( ( element ) =>
element.contains( element.ownerDocument.activeElement ),
),
).toBe( false );
} );
}
+5 -8
View File
@@ -270,7 +270,7 @@ describe( 'Related Stories progressive controllers', () => {
);
test.each( [ 'previous', 'next' ] )(
'900 to 901 moves %s focus to heading before controls hide',
'900 to 901 moves %s focus to the first card link before controls hide',
( button ) => {
const { initialize } = require( modulePath );
const media = createMedia( true );
@@ -281,6 +281,7 @@ describe( 'Related Stories progressive controllers', () => {
fixture.track.dispatchEvent( new Event( 'scroll' ) );
}
fixture[ button ].focus();
const firstLink = fixture.cards[ 0 ].querySelector( 'a' );
let focusAtHide = null;
let hidden = fixture.controls.hidden;
@@ -296,10 +297,8 @@ describe( 'Related Stories progressive controllers', () => {
} );
media.change( false );
expect( focusAtHide ).toBe( fixture.heading );
expect( document.activeElement ).toBe( fixture.heading );
expect( fixture.heading.getAttribute( 'tabindex' ) ).toBe( '-1' );
document.querySelector( '[data-unrelated]' ).focus();
expect( focusAtHide ).toBe( firstLink );
expect( document.activeElement ).toBe( firstLink );
expect( fixture.heading.hasAttribute( 'tabindex' ) ).toBe( false );
expect( fixture.controls.hidden ).toBe( true );
},
@@ -316,11 +315,9 @@ describe( 'Related Stories progressive controllers', () => {
fixture.geometry.clientWidth = fixture.geometry.scrollWidth;
window.dispatchEvent( new Event( 'resize' ) );
expect( document.activeElement ).toBe( fixture.heading );
expect( document.activeElement ).toBe( fixture.cards[ 0 ].querySelector( 'a' ) );
expect( fixture.controls.hidden ).toBe( true );
expect( fixture.next.disabled ).toBe( false );
expect( fixture.heading.getAttribute( 'tabindex' ) ).toBe( '-1' );
document.querySelector( '[data-unrelated]' ).focus();
expect( fixture.heading.hasAttribute( 'tabindex' ) ).toBe( false );
} );