feat/context-menu #10

Merged
tristonarmstrong merged 2 commits from feat/context-menu into main 2024-10-12 17:32:33 +00:00
Showing only changes of commit a2259f40ed - Show all commits

View File

@ -1,4 +1,4 @@
import { useClickOutside, useMouse } from "@kaioken-core/hooks"; import { useClickOutside, useKeyStroke, useMouse } from "@kaioken-core/hooks";
import { Portal, signal, useEffect, useRef } from "kaioken"; import { Portal, signal, useEffect, useRef } from "kaioken";
namespace ContextMenuPortal { namespace ContextMenuPortal {
@ -20,6 +20,14 @@ export function ContextMenuPortal({ children, open, closeAction }: ContextMenuPo
useEffect(() => { useEffect(() => {
if (!open) return if (!open) return
pos.value = { x: mouse.x, y: mouse.y } pos.value = { x: mouse.x, y: mouse.y }
function _handleEscapeKey(e: KeyboardEvent) {
if (e.key !== "Escape") return
closeAction?.()
}
document.addEventListener("keydown", _handleEscapeKey)
return () => {
document.removeEventListener("keydown", _handleEscapeKey)
}
}, [open]) }, [open])
if (!open) return null if (!open) return null