Skip to content

Commit

Permalink
Fix stimulus nav error in browser console
Browse files Browse the repository at this point in the history
Remove unused javascript from nav.
Use more stimulus features for greater good.
  • Loading branch information
martinemde committed Feb 8, 2024
1 parent 83f6de2 commit 171ead7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 118 deletions.
19 changes: 10 additions & 9 deletions app/javascript/controllers/nav_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ export default class extends Controller {
// * tabDirection is for hiding and showing navbar
// when you tab in and out
this.skipSandwichIcon = true;
}

document.addEventListener("click", (e) => {
// Must check both dropdowns otherwise you always close
// the dropdown because one or the other isn't being clicked
if (!this.dropdownTarget.contains(e.target) && !this.headerTarget.contains(e.target)) {
this.dropdownTarget.classList.remove('is-expanded');
this.collapseMobileNav();
}
});
clickout(e) {
if (this.headerTarget.contains(e.target)) { return }
// dropdownTarget is only present when logged in
if (this.hasDropdownTarget) {
if (this.dropdownTarget.contains(e.target)) { return }
this.dropdownTarget.classList.remove('is-expanded');
}
this.collapseMobileNav();
}

dropdownButtonTargetConnected(el) {
Expand All @@ -52,7 +53,7 @@ export default class extends Controller {

el.addEventListener('focusin', () => {
if (this.skipSandwichIcon) {
this.expandeMobileNav();
this.expandMobileNav();
this.headerSearchTarget.focus();
this.skipSandwichIcon = false;
} else {
Expand Down
16 changes: 0 additions & 16 deletions app/javascript/src/handle-click.js

This file was deleted.

70 changes: 0 additions & 70 deletions app/javascript/src/mobile-nav.js

This file was deleted.

22 changes: 0 additions & 22 deletions app/javascript/src/popup-nav.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<%= javascript_importmap_tags %>
</head>

<body class="<%= 'body--index' if request.path_info == '/' %>" data-controller="nav">
<body class="<%= 'body--index' if request.path_info == '/' %>" data-controller="nav" data-action="click@window->nav#clickout">
<!-- Top banner -->
<% if content_for?(:banner) %>
<div class="banner">
Expand Down

0 comments on commit 171ead7

Please sign in to comment.