diff --git a/assets/css/layout.css b/assets/css/layout.css index 6a4a8d0..2c05546 100644 --- a/assets/css/layout.css +++ b/assets/css/layout.css @@ -401,13 +401,7 @@ html[data-theme="light"] footer.wp-block-template-part { } .chrnx-navigation-enhanced .chrnx-theme-control { - position: relative; - z-index: 2; - display: flex; - grid-row: 1; - grid-column: 3; - width: 45px; - height: 45px; + display: contents; } .chrnx-theme-control > [data-chrnx-theme-button] { @@ -423,19 +417,25 @@ html[data-theme="light"] footer.wp-block-template-part { cursor: pointer; } + .chrnx-navigation-enhanced .chrnx-theme-control > [data-chrnx-theme-button] { + z-index: 2; + grid-row: 1; + grid-column: 3; + } + .chrnx-theme-control > [data-chrnx-theme-button][hidden], .chrnx-navigation-enhanced .chrnx-theme-toggle[hidden] { display: none; } .chrnx-navigation-enhanced .chrnx-theme-toggle { - position: absolute; - top: calc(100% + 0.25rem); - right: 0; - z-index: 1; + z-index: 2; + grid-row: 2; + grid-column: 1 / -1; + justify-self: end; flex-wrap: wrap; - width: max-content; - max-width: calc(100vw - 2rem); + width: fit-content; + max-width: 100%; min-width: 0; height: auto; padding: 0.5rem; @@ -451,8 +451,25 @@ html[data-theme="light"] footer.wp-block-template-part { .chrnx-navigation-enhanced .chrnx-theme-toggle label { flex: 1 1 auto; + min-width: 44px; + min-height: 44px; white-space: normal; } + + html[data-theme="light"] .chrnx-header-search button:focus-visible, + html[data-theme="light"] .chrnx-theme-control > [data-chrnx-theme-button]:focus-visible, + html[data-theme="light"] .chrnx-mobile-menu-toggle:focus-visible { + outline-color: var(--wp--preset--color--light-green); + } + + @media (prefers-color-scheme: light) { + + :root:not([data-theme]) .chrnx-header-search button:focus-visible, + :root:not([data-theme]) .chrnx-theme-control > [data-chrnx-theme-button]:focus-visible, + :root:not([data-theme]) .chrnx-mobile-menu-toggle:focus-visible { + outline-color: var(--wp--preset--color--light-green); + } + } } @media (prefers-reduced-motion: reduce) { diff --git a/tests/e2e/navigation.spec.mjs b/tests/e2e/navigation.spec.mjs index 9baab3d..f1ca588 100644 --- a/tests/e2e/navigation.spec.mjs +++ b/tests/e2e/navigation.spec.mjs @@ -60,6 +60,35 @@ async function expectNoHorizontalOverflow( page, header ) { ).toBe( true ); } +function parseColor( value ) { + const channels = value.match( /[\d.]+/g ).map( Number ); + if ( value.startsWith( 'color(srgb' ) ) { + return channels.slice( 0, 3 ).map( ( channel ) => channel * 255 ); + } + return channels.slice( 0, 3 ); +} + +function contrastRatio( first, second ) { + const luminance = ( color ) => { + const channels = parseColor( color ).map( ( channel ) => { + const normalized = channel / 255; + return normalized <= 0.04045 ? normalized / 12.92 : ( ( normalized + 0.055 ) / 1.055 ) ** 2.4; + } ); + return 0.2126 * channels[ 0 ] + 0.7152 * channels[ 1 ] + 0.0722 * channels[ 2 ]; + }; + const lighter = Math.max( luminance( first ), luminance( second ) ); + const darker = Math.min( luminance( first ), luminance( second ) ); + return ( lighter + 0.05 ) / ( darker + 0.05 ); +} + +async function expectContainedTarget( locator, viewportWidth ) { + const box = await getBox( locator ); + expect( box.x ).toBeGreaterThanOrEqual( 0 ); + expect( box.x + box.width ).toBeLessThanOrEqual( viewportWidth ); + expect( box.width ).toBeGreaterThanOrEqual( 44 ); + expect( box.height ).toBeGreaterThanOrEqual( 44 ); +} + test.describe( 'site navigation shell', () => { test( 'desktop has a stable accessible header, approved local brand, and compact footer', async ( { page, @@ -319,11 +348,90 @@ test.describe( 'site navigation shell', () => { const radioBox = await getBox( radio ); expect( radioBox.width ).toBeGreaterThan( 0 ); expect( radioBox.height ).toBeGreaterThan( 0 ); + await expectContainedTarget( radio.locator( '..' ), width ); } await expectNoHorizontalOverflow( page, header ); } ); } + for ( const scenario of [ 'long translated labels', '200% root text' ] ) { + test( `compact mobile header contains theme controls with ${ scenario }`, async ( { + page, + } ) => { + const width = 375; + await page.setViewportSize( { width, height: 844 } ); + await page.goto( '/' ); + if ( scenario === 'long translated labels' ) { + await page.locator( '[data-chrnx-theme-panel] label' ).evaluateAll( ( labels ) => { + const translations = [ + 'Helles Erscheinungsbild verwenden', + 'Dunkles Erscheinungsbild verwenden', + 'Automatisch dem Farbschema des Betriebssystems folgen', + ]; + labels.forEach( ( label, index ) => { + const text = Array.from( label.childNodes ).find( ( node ) => node.nodeType === 3 ); + text.nodeValue = ` ${ translations[ index ] }`; + } ); + } ); + } else { + await page.evaluate( () => { + document.documentElement.style.fontSize = '200%'; + } ); + } + + const header = page.getByRole( 'banner' ); + const panel = header.locator( '[data-chrnx-theme-panel]' ); + await header.locator( '[data-chrnx-theme-button]' ).click(); + await expect( panel ).toBeVisible(); + const contained = [ panel, ...( await panel.locator( 'label, input[type="radio"]' ).all() ) ]; + for ( const control of contained ) { + const box = await getBox( control ); + expect( box.x ).toBeGreaterThanOrEqual( 0 ); + expect( box.x + box.width ).toBeLessThanOrEqual( width ); + } + for ( const label of await panel.locator( 'label' ).all() ) { + await expectContainedTarget( label, width ); + } + await expectNoHorizontalOverflow( page, header ); + } ); + } + + for ( const colorScheme of [ 'light', 'dark' ] ) { + test( `compact mobile header has contrasting ${ colorScheme } focus outlines`, async ( { + page, + } ) => { + await page.emulateMedia( { colorScheme } ); + await page.setViewportSize( { width: 375, height: 844 } ); + await page.goto( '/' ); + await page.evaluate( ( theme ) => { + document.documentElement.dataset.theme = theme; + document.documentElement.style.colorScheme = theme; + }, colorScheme ); + const header = page.getByRole( 'banner' ); + for ( const selector of [ + '[data-chrnx-search-button]', + '[data-chrnx-theme-button]', + '[data-chrnx-menu-toggle]', + ] ) { + const control = header.locator( selector ); + await control.focus(); + const colors = await control.evaluate( ( element ) => { + const controlStyle = window.getComputedStyle( element ); + const headerStyle = window.getComputedStyle( element.closest( 'header' ) ); + return { + outline: controlStyle.outlineColor, + outlineStyle: controlStyle.outlineStyle, + outlineWidth: Number.parseFloat( controlStyle.outlineWidth ), + background: headerStyle.backgroundColor, + }; + } ); + expect( colors.outlineStyle ).not.toBe( 'none' ); + expect( colors.outlineWidth ).toBeGreaterThanOrEqual( 3 ); + expect( contrastRatio( colors.outline, colors.background ) ).toBeGreaterThanOrEqual( 3 ); + } + } ); + } + test( 'compact mobile header stops at the exact 599px boundary', async ( { page } ) => { for ( const width of [ 600, 1280 ] ) { await page.setViewportSize( { width, height: 800 } );