Skip to content

Commit b587c1b

Browse files
Dale KunceDale Kunce
authored andcommitted
fix: Implement mobile navigation menu functionality
- Add mobile-menu.js with touch/click event handling for mobile devices - Replace CSS-only hover behavior with JavaScript-based menu toggle - Add touch-friendly styling with proper cursor and tap highlight removal - Implement menu auto-close on outside click, escape key, and window resize - Ensure mobile menu works properly on devices where hover doesn't function - Mobile menu activates at screen width < 650px as per existing breakpoints
1 parent 812acb3 commit b587c1b

2 files changed

Lines changed: 60 additions & 3 deletions

File tree

app/assets/scripts/mobile-menu.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Mobile Navigation Menu
3+
* Handles touch/click events for mobile devices where hover doesn't work properly
4+
*/
5+
(function() {
6+
'use strict';
7+
8+
function initMobileMenu() {
9+
// Find the mobile dropdown toggle
10+
const mobileDropdown = document.querySelector('.resp-nav-dropdown');
11+
const dropdownContent = document.querySelector('.resp-dropdown-content');
12+
13+
if (!mobileDropdown || !dropdownContent) {
14+
return;
15+
}
16+
17+
// Add click event listener to toggle mobile menu
18+
mobileDropdown.addEventListener('click', function(e) {
19+
e.preventDefault();
20+
e.stopPropagation();
21+
22+
// Toggle the show class
23+
dropdownContent.classList.toggle('show');
24+
});
25+
26+
// Close menu when clicking outside
27+
document.addEventListener('click', function(e) {
28+
if (!mobileDropdown.contains(e.target)) {
29+
dropdownContent.classList.remove('show');
30+
}
31+
});
32+
33+
// Close menu when pressing escape key
34+
document.addEventListener('keydown', function(e) {
35+
if (e.key === 'Escape') {
36+
dropdownContent.classList.remove('show');
37+
}
38+
});
39+
40+
// Close menu when window is resized to desktop size
41+
window.addEventListener('resize', function() {
42+
if (window.innerWidth > 650) {
43+
dropdownContent.classList.remove('show');
44+
}
45+
});
46+
}
47+
48+
// Initialize when DOM is ready
49+
if (document.readyState === 'loading') {
50+
document.addEventListener('DOMContentLoaded', initMobileMenu);
51+
} else {
52+
initMobileMenu();
53+
}
54+
})();

app/assets/styles/_base.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ header{
285285
padding-left: 1em;
286286
width: 100px;
287287
cursor: pointer;
288+
-webkit-tap-highlight-color: transparent; // Remove tap highlight on mobile
289+
user-select: none; // Prevent text selection
288290
p{
289291
color: $lightgrey;
290292
font-family: 'Lato';
@@ -301,8 +303,6 @@ header{
301303
margin: 3px 0 0 0;
302304
}
303305
}
304-
&:hover{
305-
}
306306
@media screen and (max-width: 650px) {
307307
display: block;
308308
}
@@ -335,12 +335,15 @@ header{
335335
.resp-nav-dropdown {
336336
display: inline-block;
337337
text-align: center;
338+
cursor: pointer;
339+
-webkit-tap-highlight-color: transparent;
338340
@media screen and (min-width: 651px) {
339341
display: none;
340342
}
341343
}
342344

343-
.resp-nav-dropdown:hover .resp-dropdown-content {
345+
.resp-nav-dropdown:hover .resp-dropdown-content,
346+
.resp-dropdown-content.show {
344347
opacity: 1;
345348
height: auto;
346349
}

0 commit comments

Comments
 (0)