From e57deed88ba128ef162c699a07656c77a5e65de3 Mon Sep 17 00:00:00 2001 From: Mike Street Date: Fri, 18 Sep 2026 17:34:48 +0100 Subject: [PATCH] fix(modules): Fallback to fixed with if mobile html element is missing --- .github/upcoming/mobile-view-fallback.md | 3 +++ src/js/modules/mobile-view.js | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .github/upcoming/mobile-view-fallback.md diff --git a/.github/upcoming/mobile-view-fallback.md b/.github/upcoming/mobile-view-fallback.md new file mode 100644 index 0000000..c9cf617 --- /dev/null +++ b/.github/upcoming/mobile-view-fallback.md @@ -0,0 +1,3 @@ +#### Fix + +- Fallback to fixed width if mobile html element is missing diff --git a/src/js/modules/mobile-view.js b/src/js/modules/mobile-view.js index 5c92104..482af4f 100644 --- a/src/js/modules/mobile-view.js +++ b/src/js/modules/mobile-view.js @@ -12,12 +12,16 @@ export function isMobileAgent(agent = navigator.userAgent) { /** * Check if is a mobile based on selector being visible frontend + * Falls back to a screen-width check if the selector doesn't match an element * @param {string} selector + * @param {number} breakpoint - width (px) used as the mobile fallback threshold when selector isn't found * @returns {boolean} * @example isMobileView() */ -export function isMobileView(selector = '.mobileNavigation') { - return document.querySelector(selector).offsetParent !== null; +export function isMobileView(selector = '.mobileNavigation', breakpoint = 715) { + const element = document.querySelector(selector); + + return element ? element.offsetParent !== null : window.innerWidth <= breakpoint; } /**