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:
chrnxandClaude Opus 5 committed 2026-08-13 19:41:24 -05:00
1 parent f55d9d9b45
commit a142ece51d
16 files changed
+316 -156

No files matched your search

+15 -12
View File
@@ -16,17 +16,18 @@ function createMedia( matches = false ) {
function toggleMarkup() {
document.body.innerHTML = `
<fieldset class="chrnx-theme-toggle" data-chrnx-theme-toggle
<div class="chrnx-theme-toggle" role="group" aria-label="Color theme" data-chrnx-theme-toggle
data-group="theme-a"
data-status-light="Light theme active"
data-status-dark="Dark theme active"
data-status-system-light="Light theme active, following system preference"
data-status-system-dark="Dark theme active, following system preference">
<legend>Color theme</legend>
<label><input type="radio" name="theme-a" value="light">Light</label>
<label><input type="radio" name="theme-a" value="dark">Dark</label>
<label><input type="radio" name="theme-a" value="system" checked>System</label>
<span class="chrnx-theme-toggle__legend">Color theme</span>
<button type="button" data-chrnx-theme-value="light" aria-pressed="false">Light</button>
<button type="button" data-chrnx-theme-value="dark" aria-pressed="false">Dark</button>
<button type="button" data-chrnx-theme-value="system" aria-pressed="true">System</button>
<output data-chrnx-theme-status aria-live="polite">Following system theme</output>
</fieldset>`;
</div>`;
}
describe( 'theme preference helpers', () => {
@@ -85,7 +86,7 @@ describe( 'theme preference helpers', () => {
const media = createMedia( true );
expect( () => initialize( { document, storage: denied, media } ) ).not.toThrow();
expect( document.documentElement.dataset.theme ).toBe( 'dark' );
const light = document.querySelector( 'input[value="light"]' );
const light = document.querySelector( '[data-chrnx-theme-value="light"]' );
expect( () => light.click() ).not.toThrow();
expect( document.documentElement.dataset.theme ).toBe( 'light' );
} );
@@ -99,7 +100,7 @@ describe( 'theme preference helpers', () => {
expect( document.documentElement.dataset.theme ).toBe( 'light' );
media.change( true );
expect( document.documentElement.dataset.theme ).toBe( 'dark' );
document.querySelector( 'input[value="light"]' ).click();
document.querySelector( '[data-chrnx-theme-value="light"]' ).click();
media.change( false );
expect( document.documentElement.dataset.theme ).toBe( 'light' );
} );
@@ -117,10 +118,10 @@ describe( 'theme preference helpers', () => {
storage: { getItem: () => null, setItem: jest.fn(), removeItem: jest.fn() },
media,
} );
document.querySelector( 'input[name="theme-a"][value="light"]' ).click();
document.querySelector( '[data-group="theme-a"] [data-chrnx-theme-value="light"]' ).click();
expect(
[ ...document.querySelectorAll( 'input[value="light"]' ) ].every(
( input ) => input.checked,
[ ...document.querySelectorAll( '[data-chrnx-theme-value="light"]' ) ].every(
( button ) => button.getAttribute( 'aria-pressed' ) === 'true',
),
).toBe( true );
expect(
@@ -131,7 +132,9 @@ describe( 'theme preference helpers', () => {
expect( document.querySelector( '[data-chrnx-theme-status]' ).textContent ).toBe(
'Light theme active',
);
expect( document.querySelector( 'fieldset' ).textContent ).toContain( 'Color theme' );
expect( document.querySelector( '[data-chrnx-theme-toggle]' ).textContent ).toContain(
'Color theme',
);
} );
test( 'applies data-theme and color-scheme together', () => {