fix: harden CHRNX shell accessibility
This commit is contained in:
14 files changed
+520
-54
No files matched your search
+91
-11
@@ -14,6 +14,27 @@ html[data-theme="light"] h6 {
|
||||
color: var(--wp--preset--color--ink);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
|
||||
:root:not([data-theme]) {
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
:root:not([data-theme]) body {
|
||||
background: var(--wp--preset--color--paper);
|
||||
color: var(--wp--preset--color--ink);
|
||||
}
|
||||
|
||||
:root:not([data-theme]) h1,
|
||||
:root:not([data-theme]) h2,
|
||||
:root:not([data-theme]) h3,
|
||||
:root:not([data-theme]) h4,
|
||||
:root:not([data-theme]) h5,
|
||||
:root:not([data-theme]) h6 {
|
||||
color: var(--wp--preset--color--ink);
|
||||
}
|
||||
}
|
||||
|
||||
header.wp-block-template-part {
|
||||
position: sticky;
|
||||
z-index: 100;
|
||||
@@ -28,6 +49,14 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
border-bottom-color: var(--wp--preset--color--border);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
|
||||
:root:not([data-theme]) header.wp-block-template-part {
|
||||
background: color-mix(in srgb, var(--wp--preset--color--paper) 94%, transparent);
|
||||
border-bottom-color: var(--wp--preset--color--border);
|
||||
}
|
||||
}
|
||||
|
||||
.chrnx-site-header__inner,
|
||||
.chrnx-site-footer__inner {
|
||||
gap: var(--wp--preset--spacing--20) var(--wp--preset--spacing--30);
|
||||
@@ -36,6 +65,13 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
padding: var(--wp--preset--spacing--20) var(--wp--preset--spacing--30);
|
||||
}
|
||||
|
||||
.chrnx-site-footer__inner {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.chrnx-skip-link {
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
@@ -64,6 +100,23 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.chrnx-mobile-menu-toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 45px;
|
||||
min-height: 45px;
|
||||
padding: 0;
|
||||
border: 1px solid currentcolor;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.chrnx-mobile-menu-toggle[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation a,
|
||||
.chrnx-footer-navigation a,
|
||||
.wp-block-navigation__responsive-container-open,
|
||||
@@ -86,7 +139,7 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
}
|
||||
|
||||
.chrnx-header-search {
|
||||
width: min(10rem, 100%);
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.chrnx-header-search .wp-block-search__inside-wrapper {
|
||||
@@ -175,19 +228,36 @@ html[data-theme="light"] footer.wp-block-template-part {
|
||||
border-top-color: var(--wp--preset--color--border);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
|
||||
:root:not([data-theme]) footer.wp-block-template-part {
|
||||
border-top-color: var(--wp--preset--color--border);
|
||||
}
|
||||
}
|
||||
|
||||
.chrnx-site-footer__line,
|
||||
.chrnx-site-footer__inner .wp-block-site-title {
|
||||
.chrnx-site-footer__site,
|
||||
.chrnx-site-footer__credit {
|
||||
margin: 0;
|
||||
font-size: var(--wp--preset--font-size--small);
|
||||
}
|
||||
|
||||
.chrnx-footer-navigation ul {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--wp--preset--spacing--20);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
@media (max-width: 780px) {
|
||||
|
||||
.chrnx-site-header__inner {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation {
|
||||
.chrnx-primary-navigation-shell {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
@@ -205,16 +275,26 @@ html[data-theme="light"] footer.wp-block-template-part {
|
||||
|
||||
@media (max-width: 599px) {
|
||||
|
||||
html:not(.chrnx-theme-enhanced) .chrnx-primary-navigation .wp-block-navigation__responsive-container {
|
||||
display: block;
|
||||
position: static;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
.chrnx-mobile-menu-toggle {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
html:not(.chrnx-theme-enhanced) .chrnx-primary-navigation .wp-block-navigation__responsive-container-open,
|
||||
html:not(.chrnx-theme-enhanced) .chrnx-primary-navigation .wp-block-navigation__responsive-container-close {
|
||||
display: none;
|
||||
.chrnx-primary-navigation-shell {
|
||||
order: 3;
|
||||
width: 100%;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation .wp-block-navigation__container {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.chrnx-header-search {
|
||||
order: 4;
|
||||
}
|
||||
|
||||
.chrnx-theme-toggle {
|
||||
order: 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
( function () {
|
||||
'use strict';
|
||||
|
||||
let cleanupCurrent = null;
|
||||
|
||||
function initialize( options = {} ) {
|
||||
if ( cleanupCurrent ) {
|
||||
cleanupCurrent();
|
||||
}
|
||||
|
||||
const doc = options.document || ( typeof document === 'undefined' ? null : document );
|
||||
if ( ! doc ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let media = options.media;
|
||||
if ( media === undefined ) {
|
||||
try {
|
||||
media = window.matchMedia( '(max-width: 599px)' );
|
||||
} catch {
|
||||
media = null;
|
||||
}
|
||||
}
|
||||
|
||||
const buttons = [ ...doc.querySelectorAll( '[data-chrnx-menu-toggle]' ) ];
|
||||
const pairs = buttons
|
||||
.map( ( button ) => ( {
|
||||
button,
|
||||
target: doc.getElementById( button.getAttribute( 'aria-controls' ) ),
|
||||
} ) )
|
||||
.filter( ( pair ) => pair.target );
|
||||
if ( pairs.length === 0 ) {
|
||||
cleanupCurrent = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
const isMobile = () => Boolean( media && media.matches );
|
||||
const setOpen = ( pair, open, restoreFocus = false ) => {
|
||||
const expanded = isMobile() && open;
|
||||
pair.target.hidden = isMobile() && ! expanded;
|
||||
pair.button.hidden = ! isMobile();
|
||||
pair.button.setAttribute( 'aria-expanded', String( expanded ) );
|
||||
pair.button.setAttribute(
|
||||
'aria-label',
|
||||
expanded ? pair.button.dataset.labelClose : pair.button.dataset.labelOpen,
|
||||
);
|
||||
if ( restoreFocus ) {
|
||||
pair.button.focus();
|
||||
}
|
||||
};
|
||||
const reset = () => pairs.forEach( ( pair ) => setOpen( pair, false ) );
|
||||
const onClick = ( event ) => {
|
||||
const pair = pairs.find( ( candidate ) => candidate.button === event.currentTarget );
|
||||
setOpen( pair, pair.button.getAttribute( 'aria-expanded' ) !== 'true' );
|
||||
};
|
||||
const onKeydown = ( event ) => {
|
||||
if ( event.key !== 'Escape' ) {
|
||||
return;
|
||||
}
|
||||
const pair = pairs.find(
|
||||
( candidate ) => candidate.button.getAttribute( 'aria-expanded' ) === 'true',
|
||||
);
|
||||
if ( pair ) {
|
||||
setOpen( pair, false, true );
|
||||
}
|
||||
};
|
||||
|
||||
buttons.forEach( ( button ) => button.addEventListener( 'click', onClick ) );
|
||||
doc.addEventListener( 'keydown', onKeydown );
|
||||
if ( media && typeof media.addEventListener === 'function' ) {
|
||||
media.addEventListener( 'change', reset );
|
||||
}
|
||||
doc.documentElement.classList.add( 'chrnx-navigation-enhanced' );
|
||||
reset();
|
||||
|
||||
cleanupCurrent = () => {
|
||||
buttons.forEach( ( button ) => button.removeEventListener( 'click', onClick ) );
|
||||
doc.removeEventListener( 'keydown', onKeydown );
|
||||
if ( media && typeof media.removeEventListener === 'function' ) {
|
||||
media.removeEventListener( 'change', reset );
|
||||
}
|
||||
cleanupCurrent = null;
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
const helpers = { initialize };
|
||||
if ( typeof module !== 'undefined' && module.exports ) {
|
||||
module.exports = helpers;
|
||||
} else if ( typeof document !== 'undefined' ) {
|
||||
if ( document.readyState === 'loading' ) {
|
||||
document.addEventListener( 'DOMContentLoaded', () => initialize(), { once: true } );
|
||||
} else {
|
||||
initialize();
|
||||
}
|
||||
}
|
||||
} )();
|
||||
Reference in new issue
Block a user