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
+84
-40
@@ -101,26 +101,64 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.chrnx-mobile-menu-toggle {
|
||||
/* One icon language in the header: no resting outline, chip on hover/focus. */
|
||||
.chrnx-mobile-menu-toggle,
|
||||
.chrnx-header-search button,
|
||||
.chrnx-theme-control > [data-chrnx-theme-button] {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 45px;
|
||||
min-height: 45px;
|
||||
padding: 0;
|
||||
border: 1px solid currentcolor;
|
||||
border: 0;
|
||||
border-radius: 0.35rem;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font-size: 1.4rem;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.chrnx-mobile-menu-toggle[hidden] {
|
||||
.chrnx-mobile-menu-toggle:hover,
|
||||
.chrnx-mobile-menu-toggle[aria-expanded="true"],
|
||||
.chrnx-header-search button:hover,
|
||||
.chrnx-theme-control > [data-chrnx-theme-button]:hover,
|
||||
.chrnx-theme-control > [data-chrnx-theme-button][aria-expanded="true"] {
|
||||
background: color-mix(in srgb, var(--wp--preset--color--green) 24%, transparent);
|
||||
color: var(--wp--preset--color--text);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
html[data-theme="light"] .chrnx-mobile-menu-toggle:hover,
|
||||
html[data-theme="light"] .chrnx-mobile-menu-toggle[aria-expanded="true"],
|
||||
html[data-theme="light"] .chrnx-header-search button:hover,
|
||||
html[data-theme="light"] .chrnx-theme-control > [data-chrnx-theme-button]:hover,
|
||||
html[data-theme="light"] .chrnx-theme-control > [data-chrnx-theme-button][aria-expanded="true"] {
|
||||
background: color-mix(in srgb, var(--wp--preset--color--light-green) 20%, transparent);
|
||||
color: var(--wp--preset--color--ink);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
|
||||
:root:not([data-theme]) .chrnx-mobile-menu-toggle:hover,
|
||||
:root:not([data-theme]) .chrnx-mobile-menu-toggle[aria-expanded="true"],
|
||||
:root:not([data-theme]) .chrnx-header-search button:hover,
|
||||
:root:not([data-theme]) .chrnx-theme-control > [data-chrnx-theme-button]:hover,
|
||||
:root:not([data-theme]) .chrnx-theme-control > [data-chrnx-theme-button][aria-expanded="true"] {
|
||||
background: color-mix(in srgb, var(--wp--preset--color--light-green) 20%, transparent);
|
||||
color: var(--wp--preset--color--ink);
|
||||
}
|
||||
}
|
||||
|
||||
/* The shared rule above sets display, so hidden must win back explicitly. */
|
||||
.chrnx-mobile-menu-toggle[hidden],
|
||||
.chrnx-theme-control > [data-chrnx-theme-button][hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation a,
|
||||
.chrnx-footer-navigation a,
|
||||
.chrnx-header-search button,
|
||||
.chrnx-header-search input {
|
||||
min-width: 45px;
|
||||
min-height: 45px;
|
||||
@@ -155,18 +193,6 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
padding-inline: 0.75rem;
|
||||
}
|
||||
|
||||
.chrnx-header-search button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 0.75rem;
|
||||
border: 1px solid currentcolor;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.chrnx-screen-reader-text {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
@@ -193,7 +219,7 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.chrnx-theme-toggle legend {
|
||||
.chrnx-theme-toggle__legend {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
@@ -205,29 +231,50 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.chrnx-theme-toggle label {
|
||||
/* No resting outline: the active choice reads as a filled chip instead. */
|
||||
.chrnx-theme-toggle [data-chrnx-theme-value] {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 45px;
|
||||
min-height: 45px;
|
||||
padding: 0 0.45rem;
|
||||
border: 1px solid transparent;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 0.35rem;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.chrnx-theme-toggle label:has(input:checked) {
|
||||
border-color: currentcolor;
|
||||
background: var(--wp--preset--color--panel);
|
||||
.chrnx-theme-toggle [data-chrnx-theme-value] svg {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
html[data-theme="light"] .chrnx-theme-toggle label:has(input:checked) {
|
||||
background: var(--wp--preset--color--surface);
|
||||
.chrnx-theme-toggle [data-chrnx-theme-value]:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.chrnx-theme-toggle input {
|
||||
accent-color: var(--wp--preset--color--green);
|
||||
/* Quiet chip, full-contrast label: accent-on-accent fails WCAG AA. */
|
||||
.chrnx-theme-toggle [data-chrnx-theme-value][aria-pressed="true"] {
|
||||
background: color-mix(in srgb, var(--wp--preset--color--green) 24%, transparent);
|
||||
color: var(--wp--preset--color--text);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
html[data-theme="light"] .chrnx-theme-toggle [data-chrnx-theme-value][aria-pressed="true"] {
|
||||
background: color-mix(in srgb, var(--wp--preset--color--light-green) 20%, transparent);
|
||||
color: var(--wp--preset--color--ink);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
|
||||
:root:not([data-theme]) .chrnx-theme-toggle [data-chrnx-theme-value][aria-pressed="true"] {
|
||||
background: color-mix(in srgb, var(--wp--preset--color--light-green) 20%, transparent);
|
||||
color: var(--wp--preset--color--ink);
|
||||
}
|
||||
}
|
||||
|
||||
.js .chrnx-header-search[data-expanded="false"] input {
|
||||
@@ -407,16 +454,8 @@ html[data-theme="light"] footer.wp-block-template-part {
|
||||
}
|
||||
|
||||
.chrnx-theme-control > [data-chrnx-theme-button] {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 45px;
|
||||
height: 45px;
|
||||
padding: 0;
|
||||
border: 1px solid currentcolor;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.chrnx-navigation-enhanced .chrnx-theme-control > [data-chrnx-theme-button] {
|
||||
@@ -441,20 +480,25 @@ html[data-theme="light"] footer.wp-block-template-part {
|
||||
min-width: 0;
|
||||
height: auto;
|
||||
padding: 0.5rem;
|
||||
border: 1px solid currentcolor;
|
||||
border: 1px solid color-mix(in srgb, currentcolor 18%, transparent);
|
||||
border-radius: 0.35rem;
|
||||
background: var(--wp--preset--color--panel);
|
||||
color: inherit;
|
||||
box-shadow: 0 0.75rem 2rem rgb(0 0 0 / 28%);
|
||||
}
|
||||
|
||||
html[data-theme="light"].chrnx-navigation-enhanced .chrnx-theme-toggle {
|
||||
background: var(--wp--preset--color--surface);
|
||||
}
|
||||
|
||||
.chrnx-navigation-enhanced .chrnx-theme-toggle label {
|
||||
/*
|
||||
* 45px, not 44: a floor set exactly at the WCAG minimum rounds to
|
||||
* 43.99997px in Firefox and fails the target-size check.
|
||||
*/
|
||||
.chrnx-navigation-enhanced .chrnx-theme-toggle [data-chrnx-theme-value] {
|
||||
flex: 1 1 auto;
|
||||
min-width: 44px;
|
||||
min-height: 44px;
|
||||
min-width: 45px;
|
||||
min-height: 45px;
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user