Skip to content

Commit e8507fb

Browse files
authored
Fix menu behaviour on mobile devices. (#5439)
1 parent be0d040 commit e8507fb

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

themes/esphome-theme/assets/css/main.css

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,6 @@ img.align-right, figure.align-right, .figure.align-right, object.align-right {
538538
color: var(--nav-text);
539539
}
540540

541-
.dropdown:hover .dropdown-content {
542-
display: block;
543-
}
544-
545541
/* Search Box Styles */
546542
.nav-search {
547543
margin-left: 20px;
@@ -1250,13 +1246,27 @@ figcaption {
12501246
.overlay.show, .sidebar-mobile {
12511247
display: none;
12521248
}
1249+
.dropdown:hover .dropdown-content {
1250+
display: block;
1251+
}
12531252
}
12541253

1254+
/* Mobile, narrow screen. Open menu inline, hide some items */
12551255
@media (max-width: 700px) {
1256-
.desktop-only {
1257-
display: none;
1258-
}
1256+
.desktop-only {
1257+
display: none;
1258+
}
1259+
.dropdown-content {
1260+
position: relative;
1261+
width: 100%;
1262+
top: 0;
1263+
right: 0;
1264+
}
1265+
.nav-links.active {
1266+
overflow-y: auto;
1267+
}
12591268
}
1269+
12601270
/* Responsive */
12611271
/* @media (max-width: var(--mobile-width-stop)) { // sadly does not work */
12621272
@media (max-width: 1000px) {
@@ -1304,17 +1314,21 @@ figcaption {
13041314
z-index: 0;
13051315
display: none;
13061316
height: 0;
1317+
scrollbar-width: none; /* Firefox */
1318+
-ms-overflow-style: none; /* Internet Explorer 10+ */
13071319
}
13081320

13091321
.nav-links.active {
13101322
display: flex;
13111323
opacity: 100%;
13121324
z-index: 1000;
13131325
height: fit-content;
1326+
max-height: 100vh;
13141327
transition: height 0.3s ease, opacity 0.3s ease;
13151328
}
13161329

13171330
.dropdown {
1331+
position: relative;
13181332
margin-right: 0;
13191333
margin-bottom: 1em;
13201334
width: 100%;

themes/esphome-theme/assets/js/menu.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

22
const bodystyle = window.getComputedStyle(document.body);
33
const mobileWidthStop = parseInt(bodystyle.getPropertyValue('--mobile-width-stop'));
4-
const isMobile = (window.innerWidth <= mobileWidthStop);
4+
function isMobileScreen() {
5+
return (window.innerWidth <= mobileWidthStop);
6+
}
57

68
function closeMenu() {
79
const hamburger = document.querySelector('.hamburger-button');
@@ -20,7 +22,7 @@ function openMenu() {
2022
}
2123
function openTOC() {
2224
const tocToggle = document.getElementById('toc-toggle');
23-
if (!isMobile || !tocToggle) return;
25+
if (!isMobileScreen() || !tocToggle) return;
2426
const tocPanel = document.getElementsByClassName('sidebar-mobile')[0];
2527
const overlay = document.getElementById('overlay');
2628
tocToggle.classList.add('open');
@@ -30,7 +32,7 @@ function openTOC() {
3032

3133
function closeTOC() {
3234
const tocToggle = document.getElementById('toc-toggle');
33-
if (!isMobile || !tocToggle) return;
35+
if (!isMobileScreen() || !tocToggle) return;
3436
const tocPanel = document.getElementsByClassName('sidebar-mobile')[0];
3537
const overlay = document.getElementById('overlay');
3638
tocToggle.classList.remove('open');
@@ -85,7 +87,7 @@ document.addEventListener('DOMContentLoaded', function() {
8587
sidebar.addEventListener("click", closeTOC);
8688
})
8789

88-
const dropdownButtons = document.querySelectorAll('.dropbtn button');
90+
const dropdownButtons = document.querySelectorAll('.dropdown button');
8991

9092
dropdownButtons.forEach(button => {
9193
// Handle Enter and Space key presses
@@ -98,7 +100,7 @@ document.addEventListener('DOMContentLoaded', function() {
98100

99101
// Handle click events
100102
button.addEventListener('click', function(e) {
101-
if (!isMobile) return;
103+
if (!isMobileScreen()) return;
102104
e.preventDefault();
103105
// Close others
104106
dropdownButtons.forEach(function(otherBtn) {

0 commit comments

Comments
 (0)