Refactor Escape key press event
This commit is contained in:
parent
ae0d9c15fb
commit
df9c3859d2
|
@ -138,16 +138,12 @@ https://kalechips.net/projects/snippets/burger #}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.onload = () => {
|
const navbarBurger = document.querySelector(".navbar__burger");
|
||||||
const navbarBurger = document.querySelector(".navbar__burger");
|
navbarBurger.addEventListener("keydown", (event) => {
|
||||||
|
if (event.key == "Escape") {
|
||||||
navbarBurger.addEventListener("keydown", (event) => {
|
navbarBurger.removeAttribute("open");
|
||||||
const key = event.code;
|
navbarBurger.ariaExpanded = false;
|
||||||
if (key == "Escape") {
|
document.querySelector(".navbar__toggle").focus();
|
||||||
navbarBurger.removeAttribute("open");
|
}
|
||||||
navbarBurger.ariaExpanded = false;
|
});
|
||||||
document.querySelector(".navbar__toggle").focus();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue