Skip to content

Commit c9474ad

Browse files
committed
Fix isMobileNav function to prevent errors
1 parent 72874f4 commit c9474ad

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/js/utils/isMobileNav.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import getCssVar from './getCssVar'
88
* @example isMobileNav() => true; !isMobileNav() => false
99
*/
1010
export default function isMobileNav(breakpointVar = '--breakpoint-mobile-to-desktop-nav') {
11-
const breakpoint = parseInt(getCssVar(breakpointVar), 10)
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+
1225
return window.matchMedia(`(max-width: ${breakpoint - 1}px)`).matches
1326
}

0 commit comments

Comments
 (0)