Skip to content

Commit 647c4b2

Browse files
prudhvikrishnagopherbot
prudhvikrishna
authored andcommitted
_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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Jamal Carvalho <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]>
1 parent 57cac55 commit 647c4b2

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

_content/js/site.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ window.initFuncs = [];
2424
}
2525
// prevents menus that have been tabbed into from staying open
2626
// when you hover over another menu
27-
e.target.focus();
28-
e.target.blur();
27+
e.target.classList.remove('forced-closed');
28+
e.target.classList.add('forced-open');
2929
});
3030
const toggleForcedOpen = e => {
3131
const isForced = e.target.classList.contains('forced-open');
@@ -43,16 +43,17 @@ window.initFuncs = [];
4343
} else {
4444
target.classList.remove('forced-closed');
4545
target.classList.add('forced-open');
46-
target.focus();
47-
target.addEventListener('blur', e =>
48-
target.classList.remove('forced-open')
49-
);
5046
target.parentNode.removeEventListener('mouseout', () => {
5147
target.classList.remove('forced-closed');
5248
});
5349
}
50+
e.target.focus();
5451
};
5552
menuItemHover.addEventListener('click', toggleForcedOpen);
53+
menuItemHover.addEventListener('focus', e => {
54+
e.target.classList.add('forced-closed');
55+
e.target.classList.remove('forced-open');
56+
});
5657
});
5758

5859
// ensure desktop submenus are closed when esc is pressed
@@ -61,6 +62,7 @@ window.initFuncs = [];
6162
header.addEventListener('keyup', e => {
6263
if (e.key === 'Escape') {
6364
e.target.blur();
65+
e.target.focus();
6466
}
6567
});
6668
});

_content/site.tmpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@
6565
{{- $currentPage := .}}
6666
{{- range $menus.main}}
6767
<li class="Header-menuItem {{if strings.HasPrefix $currentPage.URL .url}} Header-menuItem--active{{end}}">
68-
<a href="{{if .children}}#{{else}}{{.url}}{{end}}" {{if .children}}aria-haspopup="true" class="js-desktop-menu-hover"{{end}}>
69-
{{.name}} {{if .children}}<i class="material-icons">arrow_drop_down</i>{{end}}
68+
<a href="{{if .children}}#{{else}}{{.url}}{{end}}" {{if .children}} class="js-desktop-menu-hover"{{end}} aria-label={{.name}} aria-describedby="dropdown-description">
69+
{{.name}} {{if .children}}<i class="material-icons" aria-hidden="true">arrow_drop_down</i>{{end}}
7070
</a>
71+
<div class="screen-reader-only" id="dropdown-description" hidden>
72+
Press Enter to activate/deactivate dropdown
73+
</div>
7174
{{- if .children}}
7275
<ul class="Header-submenu js-desktop-submenu-hover" aria-label="submenu">
7376
{{- range .children}}

0 commit comments

Comments
 (0)