Skip to content

Commit d75d085

Browse files
authored
Merge pull request #15 from Prakash1185/fix/mobile-topbar-click
Fix topbar menu click behavior on smaller screens
2 parents 0111754 + 4734954 commit d75d085

6 files changed

Lines changed: 37 additions & 4 deletions

File tree

.eleventy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = /** @param eleventyConfig {UserConfig} */ function (eleventyCon
3030
// be sure to add the directory to .eleventyignore
3131
eleventyConfig.addPassthroughCopy("img");
3232
eleventyConfig.addPassthroughCopy("fnt");
33+
eleventyConfig.addPassthroughCopy("js");
3334
eleventyConfig.addPassthroughCopy(".htaccess");
3435
eleventyConfig.addPassthroughCopy("robots.txt");
3536
eleventyConfig.addPassthroughCopy("asdoc");

_includes/basic.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
</div>
4343
</div>
4444
{% include "footer.html" %}
45+
<script src="/js/topbar.js"></script>
4546
</body>
4647

4748
</html>

_includes/blog-post.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
</div>
4545
</div>
4646
{% include "footer.html" %}
47+
<script src="/js/topbar.js"></script>
4748
</body>
4849

4950
</html>

_includes/marketing.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
{{ content }}
4141
</div>
4242
{% include "footer.html" %}
43+
<script src="/js/topbar.js"></script>
4344
</body>
4445

4546
</html>

_includes/sass/royale-theme-topbar.sass

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,20 @@
127127
.topMenu > li > a:hover
128128
background-color: #e7e7e7
129129

130-
.topbar-right:hover .topMenu
131-
display: flex
132-
z-index: 1000
133130

134131
@media (max-width: 599px)
135132
.topbar-left
136133
div
137-
width: 140px
134+
width: 140px
135+
136+
@media screen and (max-width: 840px)
137+
.topMenu
138+
display: none
139+
flex-direction: column
140+
position: absolute
141+
right: 10px
142+
top: 70px
143+
z-index: 1000
144+
145+
.topMenu.is-open
146+
display: flex

js/topbar.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
document.addEventListener("DOMContentLoaded", () => {
2+
const btn = document.querySelector(".topMenu-dropbtn");
3+
const menu = document.querySelector(".topMenu");
4+
5+
if (!btn || !menu) return;
6+
7+
btn.addEventListener("click", (e) => {
8+
e.preventDefault();
9+
e.stopPropagation();
10+
menu.classList.toggle("is-open");
11+
});
12+
13+
menu.addEventListener("click", (e) => {
14+
e.stopPropagation();
15+
});
16+
17+
document.addEventListener("click", () => {
18+
menu.classList.remove("is-open");
19+
});
20+
});

0 commit comments

Comments
 (0)