feat: rebuild the header controls as icon buttons
The theme switch was three labelled radios that wrapped the header onto a second line with long translations. It is three SVG buttons now, with search and menu sharing the same language: no resting outline, a filled chip for the active choice. Radios gave arrow-key roving for free, so the group reimplements it rather than losing it. The first chip colour put accent on accent and failed WCAG AA; the label carries full contrast instead. Mobile targets sit at 45px because a floor of exactly 44 rounds to 43.99997 in Firefox. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
16 files changed
+316
-156
No files matched your search
@@ -47,25 +47,31 @@ test.describe( 'real theme preference shell', () => {
|
||||
await page.goto( '/' );
|
||||
const groups = page.locator( '[data-chrnx-theme-toggle]' );
|
||||
await expect( groups.first() ).toHaveAccessibleName( 'Color theme' );
|
||||
await groups.first().getByRole( 'radio', { name: 'Light', exact: true } ).check();
|
||||
await groups.first().getByRole( 'button', { name: 'Light', exact: true } ).click();
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', 'light' );
|
||||
await expect
|
||||
.poll( () => page.evaluate( ( key ) => localStorage.getItem( key ), preferenceKey ) )
|
||||
.toBe( 'light' );
|
||||
await page.reload();
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', 'light' );
|
||||
await expect( page.getByRole( 'radio', { name: 'Light', exact: true } ) ).toBeChecked();
|
||||
await page.getByRole( 'radio', { name: 'Dark', exact: true } ).check();
|
||||
await expect( page.getByRole( 'button', { name: 'Light', exact: true } ) ).toHaveAttribute(
|
||||
'aria-pressed',
|
||||
'true',
|
||||
);
|
||||
await page.getByRole( 'button', { name: 'Dark', exact: true } ).click();
|
||||
await page.reload();
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', 'dark' );
|
||||
await expect( page.getByRole( 'radio', { name: 'Dark', exact: true } ) ).toBeChecked();
|
||||
await expect( page.getByRole( 'button', { name: 'Dark', exact: true } ) ).toHaveAttribute(
|
||||
'aria-pressed',
|
||||
'true',
|
||||
);
|
||||
const instances = await page.locator( '[data-chrnx-theme-toggle]' ).count();
|
||||
if ( instances > 1 ) {
|
||||
await expect( page.getByRole( 'radio', { name: 'Dark', exact: true } ) ).toHaveCount(
|
||||
await expect( page.getByRole( 'button', { name: 'Dark', exact: true } ) ).toHaveCount(
|
||||
instances,
|
||||
);
|
||||
for ( const radio of await page.getByRole( 'radio', { name: 'Dark', exact: true } ).all() ) {
|
||||
await expect( radio ).toBeChecked();
|
||||
for ( const radio of await page.getByRole( 'button', { name: 'Dark', exact: true } ).all() ) {
|
||||
await expect( radio ).toHaveAttribute( 'aria-pressed', 'true' );
|
||||
}
|
||||
}
|
||||
} );
|
||||
@@ -85,7 +91,10 @@ test.describe( 'real theme preference shell', () => {
|
||||
await page.reload();
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', saved );
|
||||
const savedName = saved[ 0 ].toUpperCase() + saved.slice( 1 );
|
||||
await expect( page.getByRole( 'radio', { name: savedName, exact: true } ) ).toBeChecked();
|
||||
await expect( page.getByRole( 'button', { name: savedName, exact: true } ) ).toHaveAttribute(
|
||||
'aria-pressed',
|
||||
'true',
|
||||
);
|
||||
await page.emulateMedia( { colorScheme: saved } );
|
||||
await page.emulateMedia( { colorScheme: operatingSystem } );
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', saved );
|
||||
@@ -102,7 +111,7 @@ test.describe( 'real theme preference shell', () => {
|
||||
await page.emulateMedia( { colorScheme: 'light' } );
|
||||
await page.reload();
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', 'dark' );
|
||||
await page.getByRole( 'radio', { name: 'System', exact: true } ).check();
|
||||
await page.getByRole( 'button', { name: 'System', exact: true } ).click();
|
||||
await expect
|
||||
.poll( () => page.evaluate( ( key ) => localStorage.getItem( key ), preferenceKey ) )
|
||||
.toBeNull();
|
||||
@@ -110,7 +119,10 @@ test.describe( 'real theme preference shell', () => {
|
||||
await page.emulateMedia( { colorScheme: 'dark' } );
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', 'dark' );
|
||||
await page.reload();
|
||||
await expect( page.getByRole( 'radio', { name: 'System', exact: true } ) ).toBeChecked();
|
||||
await expect( page.getByRole( 'button', { name: 'System', exact: true } ) ).toHaveAttribute(
|
||||
'aria-pressed',
|
||||
'true',
|
||||
);
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', 'dark' );
|
||||
await expect
|
||||
.poll( () => page.evaluate( ( key ) => localStorage.getItem( key ), preferenceKey ) )
|
||||
@@ -139,7 +151,7 @@ test.describe( 'real theme preference shell', () => {
|
||||
await expect( trigger ).toHaveAttribute( 'aria-expanded', 'false' );
|
||||
|
||||
await trigger.click();
|
||||
await page.getByRole( 'radio', { name: 'System', exact: true } ).focus();
|
||||
await page.getByRole( 'button', { name: 'System', exact: true } ).focus();
|
||||
await page.getByText( 'Made in Sinaloa, shared from home.', { exact: true } ).click();
|
||||
await expect( panel ).toBeHidden();
|
||||
await expect( trigger ).toBeVisible();
|
||||
@@ -176,16 +188,21 @@ test.describe( 'real theme preference shell', () => {
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', 'dark' );
|
||||
} );
|
||||
|
||||
test( 'native radios expose state, keyboard interaction, status, and 44px targets', async ( {
|
||||
test( 'native toggle buttons expose state, keyboard interaction, status, and 44px targets', async ( {
|
||||
page,
|
||||
} ) => {
|
||||
await page.goto( '/' );
|
||||
const light = page.getByRole( 'radio', { name: 'Light', exact: true } );
|
||||
const light = page.getByRole( 'button', { name: 'Light', exact: true } );
|
||||
await light.focus();
|
||||
await page.keyboard.press( 'ArrowRight' );
|
||||
await expect( page.getByRole( 'radio', { name: 'Dark', exact: true } ) ).toBeChecked();
|
||||
await expect( page.getByRole( 'button', { name: 'Dark', exact: true } ) ).toHaveAttribute(
|
||||
'aria-pressed',
|
||||
'true',
|
||||
);
|
||||
await expect( page.locator( '[data-chrnx-theme-status]' ) ).toHaveText( 'Dark theme active' );
|
||||
for ( const label of await page.locator( '[data-chrnx-theme-toggle] label' ).all() ) {
|
||||
for ( const label of await page
|
||||
.locator( '[data-chrnx-theme-toggle] [data-chrnx-theme-value]' )
|
||||
.all() ) {
|
||||
const box = await label.boundingBox();
|
||||
expect( box.width ).toBeGreaterThanOrEqual( 44 );
|
||||
expect( box.height ).toBeGreaterThanOrEqual( 44 );
|
||||
|
||||
Reference in new issue
Block a user