File tree Expand file tree Collapse file tree 7 files changed +85
-5
lines changed
Expand file tree Collapse file tree 7 files changed +85
-5
lines changed Original file line number Diff line number Diff line change 2727 <?php wp_body_open (); ?>
2828 <nav class="skip-links skip-links--hidden" aria-label="<?php esc_attr_e ( 'Fast access links ' , 'beapi-frontend-framework ' ); ?> ">
2929 <ul>
30- <li>
30+ <li class="is-desktop-only" >
3131 <a href="#menu"><?php esc_html_e ( 'Go to main navigation menu ' , 'beapi-frontend-framework ' ); ?> </a>
3232 </li>
33+ <li class="is-mobile-only">
34+ <a href="#menu-toggle"><?php esc_html_e ( 'Go to main navigation menu ' , 'beapi-frontend-framework ' ); ?> </a>
35+ </li>
3336 <li>
3437 <a href="#content"><?php esc_html_e ( 'Go to main content ' , 'beapi-frontend-framework ' ); ?> </a>
3538 </li>
4649 <span class="sr-only"><?php echo esc_html ( get_bloginfo ( 'name ' ) ); ?> </span>
4750 </a>
4851 <?php if ( has_nav_menu ( 'menu-main ' ) ) : ?>
49- <button class="header__menu-toggle" aria-expanded="false" aria-controls="menu">
52+ <button id="menu-toggle" class="header__menu-toggle" aria-expanded="false" aria-controls="menu">
5053 <span></span>
5154 <span class="sr-only aria-expanded-false-text"><?php esc_html_e ( 'Open the menu ' , 'beapi-frontend-framework ' ); ?> </span>
5255 <span class="sr-only aria-expanded-true-text"><?php esc_html_e ( 'Close the menu ' , 'beapi-frontend-framework ' ); ?> </span>
Original file line number Diff line number Diff line change 1+ /**
2+ * Get the value from a CSS custom property.
3+ *
4+ * @param {string } name CSS custom property name (ex: '--breakpoint-mobile-to-desktop-nav').
5+ * @param {HTMLElement } element The element to get the CSS custom property from.
6+ * @return {string } The value.
7+ * @example getCssVar('--breakpoint-mobile-to-desktop-nav') => '1200'
8+ */
9+ export default function getCssVar ( name , element = document . documentElement ) {
10+ if ( ! name ) {
11+ console . warn ( 'getCssVar: No name provided.' )
12+ return ''
13+ }
14+
15+ const propName = name . startsWith ( '--' ) ? name : `--${ name } `
16+
17+ return getComputedStyle ( element ) . getPropertyValue ( propName ) . trim ( )
18+ }
Original file line number Diff line number Diff line change 1+ import getCssVar from './getCssVar'
2+
3+ /**
4+ * Check if the current viewport is mobile based on a CSS breakpoint.
5+ *
6+ * @param {string } breakpointVar CSS custom property name for the breakpoint.
7+ * @return {boolean } True if viewport is mobile, false otherwise.
8+ * @example isMobileNav() => true; !isMobileNav() => false
9+ */
10+ export default function isMobileNav ( breakpointVar = '--breakpoint-mobile-to-desktop-nav' ) {
11+ const rawValue = getCssVar ( breakpointVar )
12+
13+ if ( ! rawValue ) {
14+ console . warn ( `isMobileNav: Variable ${ breakpointVar } is empty or undefined. Returning false.` )
15+ return false
16+ }
17+
18+ const breakpoint = parseInt ( rawValue , 10 )
19+
20+ if ( isNaN ( breakpoint ) ) {
21+ console . warn ( `isMobileNav: Could not parse "${ rawValue } " as a number.` )
22+ return false
23+ }
24+
25+ return window . matchMedia ( `(max-width: ${ breakpoint - 1 } px)` ) . matches
26+ }
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ $breakpoints: (
5353 admin-bar : 784 , // admin bar height change
5454 m : 960 ,
5555 md : 1080 ,
56+ mobile-to-desktop-nav : 1200 ,
5657 mdl : 1279 , // Do not use 1280px, it causes a bug under Window Edge with a device pixel ratio higher than 1
5758 l : 1440 ,
5859);
Original file line number Diff line number Diff line change 55
66:root {
77 /*
8+ * Breakpoints
9+ */
10+ --breakpoint-mobile-to-desktop-nav : #{map-get ($breakpoints , mobile-to-desktop-nav )} ; // Used by JavaScript
11+
12+ /*
813 * Heading
914 */
1015 // Font size
Original file line number Diff line number Diff line change 1+ @use " ../02-tools/m-breakpoint" as * ;
2+ @use " ../02-tools/m-style-only" as * ;
3+
4+ /* *
5+ * Display utilities
6+ *
7+ * Utility classes for showing/hiding elements based on the mobile-to-desktop-nav breakpoint.
8+ * Used primarily for skip links and navigation-related elements.
9+ */
10+
11+ // Visible only on mobile (below mobile-to-desktop-nav breakpoint)
12+ .is-mobile-only {
13+ @include breakpoints (mobile- to- desktop- nav) {
14+ @include style-only {
15+ display : none !important ;
16+ }
17+ }
18+ }
19+
20+ // Visible only on desktop (at or above mobile-to-desktop-nav breakpoint)
21+ .is-desktop-only {
22+ @include breakpoints (mobile- to- desktop- nav, max ) {
23+ @include style-only {
24+ display : none !important ;
25+ }
26+ }
27+ }
Original file line number Diff line number Diff line change 180180 }
181181 }
182182
183- @include breakpoints (mdl , max ) {
183+ @include breakpoints (mobile - to - desktop - nav , max ) {
184184 & __menu {
185185 position : absolute ;
186186 top : 0 ;
229229 }
230230 }
231231
232- @include breakpoints (sm, mdl ) {
232+ @include breakpoints (sm, mobile - to - desktop - nav ) {
233233 #{$el } __menu {
234234 right : 0 ;
235235 left : auto ;
248248 }
249249 }
250250
251- @include breakpoints (mdl ) {
251+ @include breakpoints (mobile - to - desktop - nav ) {
252252 .container {
253253 display : flex ;
254254 align-items : flex-start ;
You can’t perform that action at this time.
0 commit comments