forked from tangled.org/core
Monorepo for Tangled

appview: ui: close nav dropdowns on click outside

adds a little bit of javascript to close dropdowns in the topbar when clicking outside of them

Signed-off-by: Samuel Newman <mozzius@protonmail.com>

authored by samuel.fm and committed by Tangled 2c7dfcdd 6879ac0b

Changed files
+13 -2
appview
pages
templates
layouts
+13 -2
appview/pages/templates/layouts/topbar.html
··· 24 24 {{ end }} 25 25 26 26 {{ define "newButton" }} 27 - <details class="relative inline-block text-left"> 27 + <details class="relative inline-block text-left nav-dropdown"> 28 28 <summary class="btn-create py-0 cursor-pointer list-none flex items-center gap-2"> 29 29 {{ i "plus" "w-4 h-4" }} new 30 30 </summary> ··· 42 42 {{ end }} 43 43 44 44 {{ define "dropDown" }} 45 - <details class="relative inline-block text-left"> 45 + <details class="relative inline-block text-left nav-dropdown"> 46 46 <summary 47 47 class="cursor-pointer list-none flex items-center" 48 48 > ··· 66 66 </a> 67 67 </div> 68 68 </details> 69 + 70 + <script> 71 + document.addEventListener('click', function(event) { 72 + const dropdowns = document.querySelectorAll('.nav-dropdown'); 73 + dropdowns.forEach(function(dropdown) { 74 + if (!dropdown.contains(event.target)) { 75 + dropdown.removeAttribute('open'); 76 + } 77 + }); 78 + }); 79 + </script> 69 80 {{ end }}