astryx icon indicating copy to clipboard operation
astryx copied to clipboard

feat(core): add plugin-contributed context menus to Table

Open humbertovirtudes opened this issue 5 months ago • 3 comments

What

Adds a plugin-contributed right-click context-menu system to Table. Right-clicking a column header shows a menu of actions aggregated from every enabled plugin (instead of the browser's generic menu) — e.g. with useTableSortable enabled, right-clicking a sortable header offers Sort ascending / Sort descending / Clear sort.

Design

Plugins contribute actions rather than each rendering their own menu — the table aggregates actions from all plugins into one menu per header, avoiding nested/clobbered menus.

  • New TableContextAction type and two optional, backward-compatible TablePlugin methods: getHeaderContextActions(column, columnIndex) and getRowContextActions(item, rowIndex).
  • tableContextMenu.tsx: collectHeaderContextActions / collectRowContextActions (aggregate across plugins) + wrapInTableContextMenu (maps actions → ContextMenu options, dividers between groups, checkmark for the active item, hasAutoFocus={false} so right-click doesn't pre-highlight). When no plugin contributes actions the element is untouched and the native browser menu passes through.
  • BaseTable collects + wraps at the header render path; useBaseTablePlugins registers the two new plugin keys.
  • First contributor: useTableSortable adds asc/desc/clear (adapted to Astryx's array sort-state).

Other plugins opt in by implementing the same two methods — no core changes needed.

Scope note

Header menus only in this PR. The interface includes getRowContextActions and the row collector is built/exported, but row-menu rendering into <tr> is a follow-up: Astryx's ContextMenu wraps its trigger in a <div>, invalid between <tbody> and <tr>. Needs an asChild/Slot option on ContextMenu (or an onContextMenu-on-<tr> approach). Header menus — the sortable use case — work fully.

Demo

Surfaces on the existing Core → TableSortable stories (no new stories) — right-click any sortable column header.

Validation

  • pnpm -F @astryxdesign/core build ✅ (incl. tsc), eslint ✅
  • New tableContextMenu.test.tsx (6 tests: aggregation, header render, no-op passthrough, sortable asc/desc/clear). Full Table suite: 318 pass.
  • Changeset included ([feat]).

humbertovirtudes avatar Jun 29 '26 23:06 humbertovirtudes

@humbertovirtudes is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jun 29 '26 23:06 vercel[bot]

https://github.com/user-attachments/assets/ac663193-b67d-4a69-891e-fb84b2163aba

humbertovirtudes avatar Jun 30 '26 00:06 humbertovirtudes

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jun 30, 2026 11:35pm

Request Review

vercel[bot] avatar Jun 30 '26 02:06 vercel[bot]