Skip to content

Commit f11c743

Browse files
Add underline to active menu item on mobile devices (#72)
Co-authored-by: Paulo Valim <[email protected]> Co-authored-by: Jonatan Kłosko <[email protected]>
1 parent 7c35803 commit f11c743

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/js/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,24 @@ if (document.body.dataset.page === "integrations") {
363363
}
364364
}
365365

366+
// Add underline class to menu links on Mobile
367+
368+
function setActiveMenuItem() {
369+
const currentPath = window.location.pathname;
370+
const menuItems = document.querySelectorAll("[data-el-menu] a");
371+
372+
menuItems.forEach((item) => {
373+
const itemPathname = item.pathname;
374+
const shouldBeUnderlined =
375+
itemPathname !== "/" && currentPath.startsWith(itemPathname);
376+
377+
item.classList.toggle("border-b-2", shouldBeUnderlined);
378+
item.classList.toggle("border-gray-600", shouldBeUnderlined);
379+
});
380+
}
381+
382+
setActiveMenuItem();
383+
366384
// Change header style
367385

368386
const header = document.querySelector("#header");

src/partials/layout.html

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
</a>
5757
</div>
5858
<div class="flex-grow flex items-center justify-center">
59-
<nav class="flex space-x-12 text-gray-600">
59+
<nav data-el-menu class="flex space-x-12 text-gray-600">
6060
<a href="/#install">Install</a>
6161
<a href="/#features">Features</a>
6262
<a href="/integrations.html">Integrations</a>
@@ -116,6 +116,7 @@
116116
class="h-full mt-12 flex flex-col items-center space-y-12"
117117
>
118118
<nav
119+
data-el-menu
119120
class="flex flex-col items-center space-y-10 text-xl text-gray-700"
120121
>
121122
<a href="/#install">Install</a>
@@ -197,14 +198,12 @@
197198
<span class="mt-2 text-gray-50 text-xl font-semibold">Livebook</span>
198199
<span class="mt-1 text-gray-300">
199200
Copyright 2023. All rights reserved,
200-
<a
201-
class="border-b-2 border-gray-300"
202-
href="https://dashbit.co/"
203-
>Dashbit</a>.
204-
<a
205-
class="border-b-2 border-gray-300"
206-
href="/privacy-policy.html"
207-
>Privacy Policy</a>.
201+
<a class="border-b-2 border-gray-300" href="https://dashbit.co/"
202+
>Dashbit</a
203+
>.
204+
<a class="border-b-2 border-gray-300" href="/privacy-policy.html"
205+
>Privacy Policy</a
206+
>.
208207
</span>
209208
</div>
210209
<div class="md:hidden w-full border-t border-gray-700"></div>

0 commit comments

Comments
 (0)