From 1168c96ae22d130b81f4c7072b92127c70a66e2c Mon Sep 17 00:00:00 2001 From: Randall Stillwell Date: Wed, 11 Mar 2026 16:16:00 -0500 Subject: [PATCH] Fix right-click column visibility context menu crash Replace base-ui DropdownMenu (requires anchor trigger) with a custom positioned panel for the header right-click context menu. The base-ui Menu primitive cannot be rendered free-floating without a trigger element. Made-with: Cursor --- src/components/cards/data-table.tsx | 62 ++++++++++++++--------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/src/components/cards/data-table.tsx b/src/components/cards/data-table.tsx index b82e5dd..bf5f1af 100644 --- a/src/components/cards/data-table.tsx +++ b/src/components/cards/data-table.tsx @@ -28,13 +28,7 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; -import { - DropdownMenu, - DropdownMenuCheckboxItem, - DropdownMenuContent, - DropdownMenuLabel, - DropdownMenuSeparator, -} from "@/components/ui/dropdown-menu"; +import { Checkbox } from "@/components/ui/checkbox"; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/utils"; import type { ResponseCard } from "./columns"; @@ -120,6 +114,7 @@ export function DataTable({ x: number; y: number; } | null>(null); + const contextMenuRef = React.useRef(null); const table = useReactTable({ data, @@ -185,7 +180,15 @@ export function DataTable({ React.useEffect(() => { if (!contextMenu) return; - const close = () => setContextMenu(null); + const close = (e: MouseEvent) => { + if ( + contextMenuRef.current && + contextMenuRef.current.contains(e.target as Node) + ) { + return; + } + setContextMenu(null); + }; window.addEventListener("click", close); window.addEventListener("contextmenu", close); return () => { @@ -463,35 +466,30 @@ export function DataTable({ {/* Right-click column visibility context menu */} {contextMenu && ( - { - if (!open) setContextMenu(null); - }} +
- - Toggle Columns - - {TOGGLEABLE_COLUMNS.map((col) => ( - + Toggle Columns +
+
+ {TOGGLEABLE_COLUMNS.map((col) => ( + + ))} +
)} );