diff --git a/theme/assets/js/docs.js b/theme/assets/js/docs.js index d7f31ad..305f3ee 100644 --- a/theme/assets/js/docs.js +++ b/theme/assets/js/docs.js @@ -6,6 +6,7 @@ const drawerToggle = document.querySelector('[data-drawer-toggle]'); const drawerClose = document.querySelector('[data-drawer-close]'); const sidebar = document.querySelector('#docs-sidebar, .docs-sidebar'); + const primaryNavigation = document.querySelector('.primary-navigation'); const sidebarCollapseToggle = sidebar ? sidebar.querySelector('[data-sidebar-collapse-toggle]') : null; const sidebarContent = sidebar ? sidebar.querySelector('[data-sidebar-content]') : null; const docsShell = sidebar ? sidebar.closest('.docs-shell') : null; @@ -220,6 +221,10 @@ } if (drawerToggle) { + if (!sidebar && primaryNavigation) { + if (!primaryNavigation.id) primaryNavigation.id = 'primary-navigation'; + drawerToggle.setAttribute('aria-controls', primaryNavigation.id); + } drawerToggle.addEventListener('click', function () { setDrawer(!body.classList.contains('drawer-open')); }); diff --git a/theme/inc/blocks.php b/theme/inc/blocks.php index 5dd8a13..771f6f4 100644 --- a/theme/inc/blocks.php +++ b/theme/inc/blocks.php @@ -229,7 +229,6 @@ class="sidebar-collapse-toggle"
- 'docspress-menu-toggle' ) ); return sprintf( - '', + '', $wrapper, esc_attr( $label ), - docspress_icon( 'menu' ) + docspress_icon( 'menu' ), + esc_attr__( 'Close documentation menu', 'docspress' ) ); } diff --git a/theme/style.css b/theme/style.css index 32b6067..f2128ce 100644 --- a/theme/style.css +++ b/theme/style.css @@ -2973,6 +2973,54 @@ body.command-search-open { .docspress-menu-toggle { display: block; } + + /* + * Pages without a docs sidebar (home, posts, archives, search, 404) have + * nothing for the header drawer trigger to open. Let it reveal the + * primary navigation instead, using the same slide-in drawer treatment + * as the docs sidebar below. + */ + body:not(:has(.docs-sidebar)) .header-inner > .primary-navigation { + display: flex; + position: fixed; + top: var(--dp-header-height); + left: 0; + z-index: 90; + flex-direction: column; + align-items: stretch; + width: min(86vw, 320px); + height: calc(100vh - var(--dp-header-height)); + margin-left: 0; + padding: 16px 12px; + overflow-y: auto; + background: var(--dp-canvas); + box-shadow: var(--dp-shadow); + transform: translateX(-105%); + transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1); + } + + body.admin-bar:not(:has(.docs-sidebar)) .header-inner > .primary-navigation { + top: calc(var(--dp-header-height) + 46px); + height: calc(100vh - var(--dp-header-height) - 46px); + } + + body.drawer-open:not(:has(.docs-sidebar)) .header-inner > .primary-navigation { + transform: translateX(0); + } + + body:not(:has(.docs-sidebar)) .primary-navigation ul { + flex-direction: column; + align-items: stretch; + width: 100%; + } + + body:not(:has(.docs-sidebar)) .primary-navigation a { + width: 100%; + } + + body.drawer-open:not(:has(.docs-sidebar)) .drawer-scrim { + display: block; + } } @media (max-width: 860px) {