gpui-component icon indicating copy to clipboard operation
gpui-component copied to clipboard

DataTable: its built-in context menu takes every right-click, so a menu around the table never opens

Open since2006 opened this issue 1 week ago • 0 comments

Description

A context_menu on a container around a DataTable never opens: not on a row, not on a column header, not on the empty space below the rows. Up to 0.6 it did.

Since 0.10, ContextMenu registers its right mouse down listener before its children paint and calls cx.stop_propagation(), so of nested triggers the innermost takes the press and the outer one never sees it. That is deliberate and fine on its own. But DataTable wraps table-inner (the header and the body) in a context_menu unconditionally (table/state.rs), whose builder calls TableDelegate::context_menu(row_ix, …) only when right_clicked_row is set. The default TableDelegate::context_menu returns the menu unchanged.

So every table carries a menu trigger over all of itself, even when its delegate has no menu, and that trigger takes every right-click. The menu it builds is empty and is never drawn.

Moving the menu into the table is not a way out. TableDelegate::context_menu is only called for a row, so a table-wide menu has no hook for the header or the empty space below the rows. A delegate that wants one menu for all three has nowhere to put it.

From reading the code, Tree has the same shape: tree.rs wraps every row in a context_menu even when no builder is set. I have not tested that one.

Environment

  • GPUI: gpui-pre 0.3.14
  • GPUI Component: v0.11.0 (also v0.10.0; v0.6.1 works)
  • Platform: macOS. Reproduced in headless TestAppContext tests; nothing platform-specific.

Steps to Reproduce

A table whose delegate does not override context_menu, inside a container with a menu:

div()
    .id("list")
    .size_full()
    .context_menu(|menu, _, _| menu.menu("Refresh", Box::new(Refresh)))
    .child(DataTable::new(&table))
  1. Right-click a row, a column header, or the space below the last row.
  2. See that no menu opens.

Expected

The container's menu opens, as in 0.6. A table with no menu of its own should not take right-clicks.

Actual

No menu opens. Until #4105, focus also moved to the empty menu, which is never drawn, so actions dispatched through focus stopped working until something else took focus.

Possible fixes

These are for the maintainers to choose from:

  1. An opt-out, additive and non-breaking: for example a DataTable builder (or a TableState setting) that leaves the built-in context_menu off. Tables that use the delegate's menu keep today's behavior.
  2. An opt-in, for example TableDelegate::has_context_menu(&self) -> bool, defaulting to false. This is the cleaner default, but tables that implement context_menu today would also have to opt in.
  3. Let the delegate's menu cover the whole table: a target (row, header, empty space) instead of only row_ix. A table-wide menu could then live in the table. This changes a public trait method.

The workaround we use for now: we put the menu on an absolutely positioned layer that is painted after the table, so the layer is the innermost trigger. Rows and headers then have to record what was pressed in the capture phase, because the layer stops the press before it bubbles back to them.

since2006 avatar Nov 24 '26 13:11 since2006