fix: make CHRNX header fully progressive
This commit is contained in:
13 files changed
+414
-36
No files matched your search
+45
-9
@@ -119,10 +119,8 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
|
||||
.chrnx-primary-navigation a,
|
||||
.chrnx-footer-navigation a,
|
||||
.wp-block-navigation__responsive-container-open,
|
||||
.wp-block-navigation__responsive-container-close,
|
||||
.chrnx-header-search .wp-block-search__button,
|
||||
.chrnx-header-search .wp-block-search__input {
|
||||
.chrnx-header-search button,
|
||||
.chrnx-header-search input {
|
||||
min-width: 45px;
|
||||
min-height: 45px;
|
||||
}
|
||||
@@ -134,16 +132,50 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
padding-inline: 0.55rem;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation .wp-block-navigation__container {
|
||||
.chrnx-primary-navigation ul {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.chrnx-header-search {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.chrnx-header-search .wp-block-search__inside-wrapper {
|
||||
.chrnx-header-search input {
|
||||
box-sizing: border-box;
|
||||
width: min(15rem, 45vw);
|
||||
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;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.chrnx-theme-toggle {
|
||||
@@ -197,6 +229,10 @@ html[data-theme="light"] .chrnx-theme-toggle label:has(input:checked) {
|
||||
accent-color: var(--wp--preset--color--green);
|
||||
}
|
||||
|
||||
.js .chrnx-header-search[data-expanded="false"] input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.chrnx-theme-toggle output {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
@@ -257,7 +293,7 @@ html[data-theme="light"] footer.wp-block-template-part {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation-shell {
|
||||
.chrnx-primary-navigation {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
@@ -279,13 +315,13 @@ html[data-theme="light"] footer.wp-block-template-part {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation-shell {
|
||||
.chrnx-primary-navigation {
|
||||
order: 3;
|
||||
width: 100%;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation .wp-block-navigation__container {
|
||||
.chrnx-primary-navigation ul {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,15 @@
|
||||
pair.button.focus();
|
||||
}
|
||||
};
|
||||
const reset = () => pairs.forEach( ( pair ) => setOpen( pair, false ) );
|
||||
const reset = () =>
|
||||
pairs.forEach( ( pair ) => {
|
||||
const wasInsideTarget = pair.target.contains( doc.activeElement );
|
||||
const becomingMobile = isMobile();
|
||||
setOpen( pair, false );
|
||||
if ( becomingMobile && wasInsideTarget ) {
|
||||
pair.button.focus();
|
||||
}
|
||||
} );
|
||||
const onClick = ( event ) => {
|
||||
const pair = pairs.find( ( candidate ) => candidate.button === event.currentTarget );
|
||||
setOpen( pair, pair.button.getAttribute( 'aria-expanded' ) !== 'true' );
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
( 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;
|
||||
}
|
||||
|
||||
const forms = [ ...doc.querySelectorAll( '[data-chrnx-search]' ) ];
|
||||
const controls = forms
|
||||
.map( ( form ) => ( {
|
||||
form,
|
||||
input: form.querySelector( 'input[name="s"]' ),
|
||||
button: form.querySelector( '[data-chrnx-search-button]' ),
|
||||
} ) )
|
||||
.filter( ( control ) => control.input && control.button );
|
||||
if ( controls.length === 0 ) {
|
||||
cleanupCurrent = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
const setExpanded = ( control, expanded, restoreFocus = false ) => {
|
||||
control.form.dataset.expanded = String( expanded );
|
||||
control.input.hidden = ! expanded;
|
||||
control.button.setAttribute(
|
||||
'aria-label',
|
||||
expanded ? control.button.dataset.labelSubmit : control.button.dataset.labelOpen,
|
||||
);
|
||||
if ( expanded ) {
|
||||
control.input.focus();
|
||||
} else if ( restoreFocus ) {
|
||||
control.button.focus();
|
||||
}
|
||||
};
|
||||
const onSubmit = ( event ) => {
|
||||
const control = controls.find( ( candidate ) => candidate.form === event.currentTarget );
|
||||
if ( ! control.input.value.trim() ) {
|
||||
event.preventDefault();
|
||||
setExpanded( control, true );
|
||||
}
|
||||
};
|
||||
const onKeydown = ( event ) => {
|
||||
if ( event.key !== 'Escape' ) {
|
||||
return;
|
||||
}
|
||||
const control = controls.find(
|
||||
( candidate ) =>
|
||||
candidate.form.dataset.expanded === 'true' && candidate.form.contains( event.target ),
|
||||
);
|
||||
if ( control ) {
|
||||
event.preventDefault();
|
||||
setExpanded( control, false, true );
|
||||
}
|
||||
};
|
||||
|
||||
controls.forEach( ( control ) => {
|
||||
setExpanded( control, false );
|
||||
control.form.addEventListener( 'submit', onSubmit );
|
||||
} );
|
||||
doc.addEventListener( 'keydown', onKeydown );
|
||||
|
||||
cleanupCurrent = () => {
|
||||
controls.forEach( ( control ) => control.form.removeEventListener( 'submit', onSubmit ) );
|
||||
doc.removeEventListener( 'keydown', onKeydown );
|
||||
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