Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

609 B
Raw Blame
import { useEffect } from "react";
import { shouldLeaveOnEscape } from "@/components/settings/nav/should-leave-on-escape";

export function useLeaveSettingsOnEscape(onLeave: (() => void) | undefined) {
  useEffect(() => {
    if (!onLeave) return;

    const handleKeyDown = (event: KeyboardEvent) => {
      if (shouldLeaveOnEscape(event, document)) onLeave();
    };

    // Capture runs before overlays handle Escape, while they are still open.
    document.addEventListener("keydown", handleKeyDown, true);
    return () => document.removeEventListener("keydown", handleKeyDown, true);
  }, [onLeave]);
}