From 001d2802dec4bc846551bbf5a3edc66ecf99bfa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Augusto?= Date: Thu, 4 Jun 2026 11:19:38 +0100 Subject: [PATCH 1/2] fix(javascript): Fix isMobileView fallback when mobile nav is missing Resolve #1 --- UPCOMING.md | 3 +++ src/js/modules/mobile-view.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/UPCOMING.md b/UPCOMING.md index e69de29..675007d 100644 --- a/UPCOMING.md +++ b/UPCOMING.md @@ -0,0 +1,3 @@ +# Fix + +- Fixed `isMobileView()` so it no longer throws when the default `.mobileNavigation` element is missing. Falls back to a `715px` viewport-width check diff --git a/src/js/modules/mobile-view.js b/src/js/modules/mobile-view.js index 5c92104..9695a0c 100644 --- a/src/js/modules/mobile-view.js +++ b/src/js/modules/mobile-view.js @@ -1,5 +1,7 @@ import { debounce } from '../index'; +const DEFAULT_MOBILE_VIEW_MAX_WIDTH = 715; + /** * Check if is a mobile device based on Agent * @param {string} agent @@ -13,11 +15,18 @@ export function isMobileAgent(agent = navigator.userAgent) { /** * Check if is a mobile based on selector being visible frontend * @param {string} selector + * @param {number} fallbackWidth * @returns {boolean} * @example isMobileView() */ -export function isMobileView(selector = '.mobileNavigation') { - return document.querySelector(selector).offsetParent !== null; +export function isMobileView(selector = '.mobileNavigation', fallbackWidth = DEFAULT_MOBILE_VIEW_MAX_WIDTH) { + const element = document.querySelector(selector); + + if (element) { + return element.offsetParent !== null; + } + + return window.matchMedia(`(max-width: ${fallbackWidth}px)`).matches; } /** From 346d596f28792d01c51304e54cd33fc07772c251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Augusto?= <105639732+joaoliquidlight@users.noreply.github.com> Date: Thu, 4 Jun 2026 13:00:38 +0100 Subject: [PATCH 2/2] Update src/js/modules/mobile-view.js Co-authored-by: Mike Street --- src/js/modules/mobile-view.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/js/modules/mobile-view.js b/src/js/modules/mobile-view.js index 9695a0c..591f933 100644 --- a/src/js/modules/mobile-view.js +++ b/src/js/modules/mobile-view.js @@ -22,11 +22,9 @@ export function isMobileAgent(agent = navigator.userAgent) { export function isMobileView(selector = '.mobileNavigation', fallbackWidth = DEFAULT_MOBILE_VIEW_MAX_WIDTH) { const element = document.querySelector(selector); - if (element) { - return element.offsetParent !== null; - } - - return window.matchMedia(`(max-width: ${fallbackWidth}px)`).matches; + return element ? + (element.offsetParent !== null) : + window.matchMedia(`(max-width: ${fallbackWidth}px)`).matches; } /**