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
+20
-16
@@ -46,11 +46,11 @@ function shellMarkup() {
|
||||
<div data-part="theme" class="chrnx-theme-control">
|
||||
<button hidden type="button" data-chrnx-theme-button
|
||||
aria-controls="chrnx-theme-panel" aria-expanded="false">Theme</button>
|
||||
<fieldset id="chrnx-theme-panel" data-chrnx-theme-panel data-chrnx-theme-toggle>
|
||||
<label><input type="radio" name="theme" value="light"> Light</label>
|
||||
<label><input type="radio" name="theme" value="dark"> Dark</label>
|
||||
<label><input type="radio" name="theme" value="system" checked> System</label>
|
||||
</fieldset>
|
||||
<div id="chrnx-theme-panel" role="group" aria-label="Color theme" data-chrnx-theme-panel data-chrnx-theme-toggle>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<button data-outside>Outside</button>
|
||||
@@ -72,8 +72,10 @@ function controls() {
|
||||
theme: document.querySelector( '[data-part="theme"]' ),
|
||||
themeButton: document.querySelector( '[data-chrnx-theme-button]' ),
|
||||
themePanel: document.querySelector( '[data-chrnx-theme-panel]' ),
|
||||
checkedRadio: document.querySelector( '[data-chrnx-theme-panel] input:checked' ),
|
||||
firstRadio: document.querySelector( '[data-chrnx-theme-panel] input' ),
|
||||
checkedRadio: document.querySelector(
|
||||
'[data-chrnx-theme-panel] [data-chrnx-theme-value][aria-pressed="true"]',
|
||||
),
|
||||
firstRadio: document.querySelector( '[data-chrnx-theme-panel] [data-chrnx-theme-value]' ),
|
||||
outside: document.querySelector( '[data-outside]' ),
|
||||
outsideContent: document.querySelector( '[data-outside-content]' ),
|
||||
};
|
||||
@@ -104,10 +106,10 @@ function visibleFocusableElements() {
|
||||
if ( element.hidden || element.closest( '[hidden]' ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( element.type !== 'radio' || element.checked ) {
|
||||
if ( ! element.dataset.chrnxThemeValue ) {
|
||||
return true;
|
||||
}
|
||||
return ! document.querySelector( `input[type="radio"][name="${ element.name }"]:checked` );
|
||||
return element.getAttribute( 'aria-pressed' ) === 'true';
|
||||
} );
|
||||
}
|
||||
|
||||
@@ -331,7 +333,7 @@ describe( 'coordinated CHRNX header shell', () => {
|
||||
initialize( { document, media: createMedia( true ) } );
|
||||
const control = controls();
|
||||
control[ buttonName ].click();
|
||||
control[ panelName ].querySelector( 'input, a' ).focus();
|
||||
control[ panelName ].querySelector( 'input, a, button' ).focus();
|
||||
press( control[ panelName ], 'Escape' );
|
||||
expect( control[ panelName ].hidden ).toBe( true );
|
||||
expect( document.activeElement ).toBe( control[ buttonName ] );
|
||||
@@ -435,9 +437,11 @@ describe( 'coordinated CHRNX header shell', () => {
|
||||
const media = createMedia( true );
|
||||
initialize( { document, media } );
|
||||
const control = controls();
|
||||
const currentRadio = control.themePanel.querySelector( `input[value="${ value }"]` );
|
||||
control.checkedRadio.checked = false;
|
||||
currentRadio.checked = true;
|
||||
const currentRadio = control.themePanel.querySelector(
|
||||
`[data-chrnx-theme-value="${ value }"]`,
|
||||
);
|
||||
control.checkedRadio.setAttribute( 'aria-pressed', 'false' );
|
||||
currentRadio.setAttribute( 'aria-pressed', 'true' );
|
||||
control.themeButton.focus();
|
||||
|
||||
media.change( false );
|
||||
@@ -450,8 +454,8 @@ describe( 'coordinated CHRNX header shell', () => {
|
||||
const media = createMedia( true );
|
||||
initialize( { document, media } );
|
||||
const control = controls();
|
||||
control.themePanel.querySelectorAll( 'input[type="radio"]' ).forEach( ( radio ) => {
|
||||
radio.checked = false;
|
||||
control.themePanel.querySelectorAll( '[data-chrnx-theme-value]' ).forEach( ( radio ) => {
|
||||
radio.setAttribute( 'aria-pressed', 'false' );
|
||||
} );
|
||||
control.themeButton.focus();
|
||||
|
||||
@@ -562,7 +566,7 @@ describe( 'coordinated CHRNX header shell', () => {
|
||||
test.each( [
|
||||
[ 'brand', '.chrnx-site-brand' ],
|
||||
[ 'navigation link', '[data-part="nav"] a' ],
|
||||
[ 'theme radio', '[data-chrnx-theme-panel] input' ],
|
||||
[ 'theme button', '[data-chrnx-theme-panel] [data-chrnx-theme-value]' ],
|
||||
] )( 'fails closed without the required %s', ( _name, selector ) => {
|
||||
const { initialize } = require( modulePath );
|
||||
document.querySelectorAll( selector ).forEach( ( element ) => element.remove() );
|
||||
|
||||
Reference in new issue
Block a user