diff --git a/src/components/menu.tsx b/src/components/menu.tsx index 604e2fb..5b9abe2 100644 --- a/src/components/menu.tsx +++ b/src/components/menu.tsx @@ -40,24 +40,32 @@ const MyMenu: Component = ( } } + function keypress(e: KeyboardEvent): void { + if (e.key === "Escape") { + closeMenu(); + } + } + if (isOpen()) { document.addEventListener("click", click); + document.addEventListener("keyup", keypress); } else { document.removeEventListener("click", click); + document.removeEventListener("keyup", keypress); } }); return ( // TODO transition
- - +
{ children }