"use client"; import Link from "next/link"; import { MoreHorizontal } from "lucide-react"; import { useEffect, useId, useRef, useState } from "react"; import type { AiToolItem } from "@/lib/nav/ai-tools"; import type { ActiveNav } from "@/lib/nav/items"; import { buttonClass, cn, focusRing } from "@/lib/ui/variants"; interface AiToolbarMoreMenuProps { items: AiToolItem[]; activeNav?: ActiveNav; } export function AiToolbarMoreMenu({ items, activeNav, }: AiToolbarMoreMenuProps) { const [open, setOpen] = useState(false); const menuId = useId(); const rootRef = useRef(null); const buttonRef = useRef(null); useEffect(() => { if (!open) return; const onKeyDown = (event: KeyboardEvent): void => { if (event.key === "Escape") { setOpen(false); buttonRef.current?.focus(); } }; const onPointerDown = (event: PointerEvent): void => { const target = event.target; if (target instanceof Node && !rootRef.current?.contains(target)) { setOpen(false); } }; window.addEventListener("keydown", onKeyDown); window.addEventListener("pointerdown", onPointerDown); return () => { window.removeEventListener("keydown", onKeyDown); window.removeEventListener("pointerdown", onPointerDown); }; }, [open]); return (
{open ? ( // 诚实的 Tab-only 折叠面板:普通导航链接,不冒充 ARIA menu(无 roving tabindex/方向键)。 ) : null}
); }