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

+2 -2
View File
@@ -50,7 +50,7 @@
const shell = menuButton && menuButton.parentElement;
const brand = shell && shell.querySelector( '.chrnx-site-brand' );
const navLink = nav && nav.querySelector( 'a[href]' );
const themeRadio = themePanel && themePanel.querySelector( 'input[type="radio"]' );
const themeRadio = themePanel && themePanel.querySelector( '[data-chrnx-theme-value]' );
const required = [
menuButton,
nav,
@@ -107,7 +107,7 @@
let activePanel = null;
const currentThemeRadio = () =>
themePanel.querySelector( 'input[type="radio"]:checked' ) || themeRadio;
themePanel.querySelector( '[data-chrnx-theme-value][aria-pressed="true"]' ) || themeRadio;
const restoreOriginalOrder = () => {
elements.forEach( ( element ) => {
const anchor = anchors.get( element );
+41 -5
View File
@@ -77,7 +77,9 @@
}
}
const controls = [ ...doc.querySelectorAll( '[data-chrnx-theme-toggle] input[type="radio"]' ) ];
const controls = [
...doc.querySelectorAll( '[data-chrnx-theme-toggle] [data-chrnx-theme-value]' ),
];
const groups = [ ...doc.querySelectorAll( '[data-chrnx-theme-toggle]' ) ];
let explicitPreference = readPreference( storage );
let listening = false;
@@ -89,7 +91,8 @@
applyTheme( doc, resolved );
const selected = explicitPreference || 'system';
controls.forEach( ( control ) => {
control.checked = control.value === selected;
const pressed = control.dataset.chrnxThemeValue === selected;
control.setAttribute( 'aria-pressed', String( pressed ) );
} );
groups.forEach( ( group ) => {
const status = group.querySelector( '[data-chrnx-theme-status]' );
@@ -119,19 +122,52 @@
listening = shouldListen;
};
const onChange = ( event ) => {
const value = event.currentTarget.value;
const value = event.currentTarget.dataset.chrnxThemeValue;
explicitPreference = normalizePreference( value );
writePreference( storage, value );
setMediaListening( ! explicitPreference );
update();
};
controls.forEach( ( control ) => control.addEventListener( 'change', onChange ) );
// Buttons do not get the arrow-key roving a native radio group provides,
// so the group reimplements it: move focus and select, like radios did.
const STEPS = { ArrowLeft: -1, ArrowUp: -1, ArrowRight: 1, ArrowDown: 1 };
const onKeydown = ( event ) => {
const step = STEPS[ event.key ];
const toStart = event.key === 'Home';
const toEnd = event.key === 'End';
if ( step === undefined && ! toStart && ! toEnd ) {
return;
}
const group = event.currentTarget.closest( '[data-chrnx-theme-toggle]' );
const siblings = group ? [ ...group.querySelectorAll( '[data-chrnx-theme-value]' ) ] : [];
const index = siblings.indexOf( event.currentTarget );
if ( index < 0 ) {
return;
}
event.preventDefault();
let next = 0;
if ( toEnd ) {
next = siblings.length - 1;
} else if ( ! toStart ) {
next = ( index + step + siblings.length ) % siblings.length;
}
siblings[ next ].focus();
siblings[ next ].click();
};
controls.forEach( ( control ) => {
control.addEventListener( 'click', onChange );
control.addEventListener( 'keydown', onKeydown );
} );
setMediaListening( ! explicitPreference );
update();
cleanupCurrent = () => {
controls.forEach( ( control ) => control.removeEventListener( 'change', onChange ) );
controls.forEach( ( control ) => {
control.removeEventListener( 'click', onChange );
control.removeEventListener( 'keydown', onKeydown );
} );
setMediaListening( false );
cleanupCurrent = null;
};