Skip to content

useContextMenuHandlers

useContextMenuHandlers<TData>(): object

Defined in: contextMenu.tsx:492

Hook to get context menu handlers for table cells and column headers.

This hook provides event handlers that:

  • Prevent default browser context menu
  • Calculate element position (DOMRect)
  • Open the appropriate context menu type

TData

Object with handleCellContextMenu and handleColumnContextMenu functions

handleCellContextMenu: (e, cell, column, row) => void

Handler for cell context menu events. Call this in the onContextMenu prop of table cells.

MouseEvent<HTMLTableCellElement>

Cell<TData, unknown>

Column<TData, unknown>

Row<TData>

void

handleColumnContextMenu: (e, column) => void

Handler for column header context menu events. Call this in the onContextMenu prop of table header cells.

MouseEvent<HTMLTableCellElement>

Column<TData, unknown>

void

const handlers = useContextMenuHandlers<Person>();
<td onContextMenu={(e) => handlers.handleCellContextMenu(e, cell, column, row)}>
{content}
</td>
<th onContextMenu={(e) => handlers.handleColumnContextMenu(e, column)}>
{header}
</th>