From a2743722c61d9597f3c40e07e2cc6091f5e9b277 Mon Sep 17 00:00:00 2001 From: Yevhenii Hurin Date: Sat, 7 Oct 2023 21:23:51 +0300 Subject: [PATCH] Fix mobile navigation (#27) --- app/javascript/application.js | 15 +++++++++++++++ app/views/shared/_navbar.html.slim | 11 +++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/javascript/application.js b/app/javascript/application.js index b9f57c5..5308318 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -2,3 +2,18 @@ import "@hotwired/turbo-rails" import "./controllers" import "chartkick/highcharts" + +// navbar burger +document.addEventListener('turbo:load', () => { + const navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0); + if (navbarBurgers.length > 0) { + navbarBurgers.forEach(el => { + el.addEventListener('click', () => { + const target = el.dataset.target; + const $target = document.getElementById(target); + el.classList.toggle('is-active'); + $target.classList.toggle('is-active'); + }); + }); + } +}); diff --git a/app/views/shared/_navbar.html.slim b/app/views/shared/_navbar.html.slim index d2cc1a4..f3ba378 100644 --- a/app/views/shared/_navbar.html.slim +++ b/app/views/shared/_navbar.html.slim @@ -1,12 +1,11 @@ -header.navbar - .container +header + nav.navbar role="navigation" aria-label="main navigation" .navbar-brand a.navbar-item href="/" | X-Tracker - span.navbar-burger.burger data-target="navbarMenuHeroA" - span - span - span + a.navbar-burger.burger data-target="navbarMenuHeroA" role="button" aria-label="menu" aria-expanded="false" + span aria-hidden="true" + span aria-hidden="true" .navbar-menu id="navbarMenuHeroA" .navbar-end a.navbar-item href="/"