Row Context Menu Table
One row menu that powers both the "..." dropdown and the right-click context menu.
Gives every row a right-click context menu that matches its “…” (kebab) actions. You define the actions once and they show in both places. Right-click a row or open the ⋯ menu: both run the same actions.
Overview
Section titled “Overview”Introduction
Section titled “Introduction”This is the composable, shadcn-style way to do row actions. Write the actions once as a small component. Then use that same component in the kebab cell and in the body’s context-menu slot. No copied item lists, and no (row) => ... render function at the call site.
Three pieces make it work:
DataTableRowContextMenuSlot: nest it inside aDataTableBodyorDataTableVirtualizedBody.- It renders nothing itself.
- The body finds it and adds a right-click menu to every row, wrapped in a scope that carries the row.
DataTableRowMenuScope: gives the nested pieces the currentrowand thesurface("dropdown"or"context").- The context-menu body sets this up for you.
- For the kebab, you wrap it around your
DropdownMenuContentchildren.
- Polymorphic
RowMenuItem/RowMenuSeparator/RowMenuSub/ …: each renders as the dropdown piece or the context-menu piece, based on the surface it reads from context. Use them likeDropdownMenuItems.
Read the row inside your menu component with useDataTableRow<T>(). The same element then works for every row.
Anatomy
Section titled “Anatomy”// 1. Define the actions ONCE — reads its row from context.function PlayerRowMenu({ onView, onRemove }: PlayerRowMenuProps) { const player = useDataTableRow<Player>() return ( <> <RowMenuItem onClick={() => onView(player)}>View profile</RowMenuItem> <RowMenuSeparator /> <RowMenuItem variant="destructive" onClick={() => onRemove(player)}> Remove player </RowMenuItem> </> )}
const rowMenu = <PlayerRowMenu onView={onView} onRemove={onRemove} />
// 2. Kebab cell — same element, rendered as a dropdown.<DropdownMenuContent align="end"> <DataTableRowMenuScope row={row.original} surface="dropdown"> {rowMenu} </DataTableRowMenuScope></DropdownMenuContent>
// 3. Right-click — same element, rendered as a context menu.<DataTableBody> <DataTableRowContextMenuSlot>{rowMenu}</DataTableRowContextMenuSlot></DataTableBody>Per-row opt-out
Section titled “Per-row opt-out”To hide the menu for some rows (locked, read-only, and so on), pass an enabledFor function to the slot. Return false and that row gets no menu:
<DataTableRowContextMenuSlot enabledFor={(row) => !row.isLocked}> {rowMenu}</DataTableRowContextMenuSlot>To turn the menu off for the whole table (for example, no manage permission), don’t render the slot.
Installation
Section titled “Installation”The row menu ships with the DataTable core:
pnpm dlx shadcn@latest add @niko-table/data-tableFirst time using
@niko-table? See the Installation Guide to set up the registry.