_content: made content activated by mouse dismissible using ESC key
https://screencast.googleplex.com/cast/NTcyNjIwNDA4MTQ3MTQ4OHwxOTQwNzQyNS04ZA Change-Id: I4c804d97c7485cf75ea16260a6d4143cf0a70f69 Reviewed-on: https://go-review.googlesource.com/c/website/+/516196 Reviewed-by: Neelesh Bodas <neelesh@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org> Run-TryBot: Jamal Carvalho <jamal@golang.org> Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Родитель
e98120d599
Коммит
2c2263031c
|
@ -54,17 +54,20 @@ window.initFuncs = [];
|
|||
e.target.classList.add('forced-closed');
|
||||
e.target.classList.remove('forced-open');
|
||||
});
|
||||
});
|
||||
|
||||
// ensure desktop submenus are closed when esc is pressed
|
||||
const headerItems = document.querySelectorAll('.Header-menuItem');
|
||||
headerItems.forEach(header => {
|
||||
header.addEventListener('keyup', e => {
|
||||
// ensure desktop submenus are closed when esc is pressed
|
||||
const closeSubmenuOnEsc = e => {
|
||||
if (e.key === 'Escape') {
|
||||
e.target.blur();
|
||||
e.target.focus();
|
||||
const forcedOpenItem = document.querySelector('.forced-open');
|
||||
const target = e.currentTarget;
|
||||
if (forcedOpenItem) {
|
||||
forcedOpenItem.classList.remove('forced-open');
|
||||
forcedOpenItem.blur();
|
||||
forcedOpenItem.classList.add('forced-closed');
|
||||
}
|
||||
}
|
||||
});
|
||||
e.target.focus();
|
||||
};
|
||||
document.addEventListener('keydown', closeSubmenuOnEsc);
|
||||
});
|
||||
|
||||
// Mobile menu subnav menus
|
||||
|
|
Загрузка…
Ссылка в новой задаче