From 647c4b2c5ac6204d03a40c19f7ec23ccd272caea Mon Sep 17 00:00:00 2001 From: prudhvikrishna Date: Fri, 14 Jul 2023 12:35:47 -0700 Subject: [PATCH] _content: fix for dropdown to not autoopen when receive focus Change-Id: Iee3897aa4f5c1311141411ec44193751cb516e4d Reviewed-on: https://go-review.googlesource.com/c/website/+/509857 Auto-Submit: Jamal Carvalho TryBot-Result: Gopher Robot Run-TryBot: Jamal Carvalho Reviewed-by: Jamal Carvalho --- _content/js/site.js | 14 ++++++++------ _content/site.tmpl | 7 +++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/_content/js/site.js b/_content/js/site.js index 79c3c888..eecd9add 100644 --- a/_content/js/site.js +++ b/_content/js/site.js @@ -24,8 +24,8 @@ window.initFuncs = []; } // prevents menus that have been tabbed into from staying open // when you hover over another menu - e.target.focus(); - e.target.blur(); + e.target.classList.remove('forced-closed'); + e.target.classList.add('forced-open'); }); const toggleForcedOpen = e => { const isForced = e.target.classList.contains('forced-open'); @@ -43,16 +43,17 @@ window.initFuncs = []; } else { target.classList.remove('forced-closed'); target.classList.add('forced-open'); - target.focus(); - target.addEventListener('blur', e => - target.classList.remove('forced-open') - ); target.parentNode.removeEventListener('mouseout', () => { target.classList.remove('forced-closed'); }); } + e.target.focus(); }; menuItemHover.addEventListener('click', toggleForcedOpen); + menuItemHover.addEventListener('focus', e => { + e.target.classList.add('forced-closed'); + e.target.classList.remove('forced-open'); + }); }); // ensure desktop submenus are closed when esc is pressed @@ -61,6 +62,7 @@ window.initFuncs = []; header.addEventListener('keyup', e => { if (e.key === 'Escape') { e.target.blur(); + e.target.focus(); } }); }); diff --git a/_content/site.tmpl b/_content/site.tmpl index bcd54a6b..975faf89 100644 --- a/_content/site.tmpl +++ b/_content/site.tmpl @@ -65,9 +65,12 @@ {{- $currentPage := .}} {{- range $menus.main}}
  • - - {{.name}} {{if .children}}arrow_drop_down{{end}} + + {{.name}} {{if .children}}{{end}} + {{- if .children}}
      {{- range .children}}