Skip to content

feat: pass clicked column to grid context menu dynamic content provider - #10331

Merged
sissbruecker merged 9 commits into
mainfrom
fix/grid-context-menu-dynamic-handler-column
Oct 5, 2026
Merged

sissbruecker merged 9 commits into
mainfrom
fix/grid-context-menu-dynamic-handler-column

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review risk: two-way door — additive API on GridContextMenu plus deprecation of the item-only dynamic content handler.

Summary

The dynamic content handler of GridContextMenu only received the clicked item, so there was no supported way to know which column was right-clicked when building the menu.

This adds a dynamic content provider that receives a context record with the clicked item and column, which enables context menus whose items depend on the column that was right-clicked:

contextMenu.setDynamicContentProvider(context -> {
    contextMenu.removeAll();
    Person person = context.item();
    if (context.column() == nameColumn) {
        contextMenu.addItem("Call", e -> call(person));
    } else if (context.column() == addressColumn) {
        contextMenu.addItem("Show on map", e -> showOnMap(person));
    }
    return true;
});

What changed

  • New GridContextMenu#setDynamicContentProvider(SerializablePredicate<DynamicContentContext<T>>) / getDynamicContentProvider() and the GridContextMenu.DynamicContentContext<T>(T item, Grid.Column<T> column) record. column is null when the click doesn't target an application column (e.g. the selection column), item is null when it doesn't target an item (e.g. a header). The column is resolved from its internal id, so it works without Column#setId. Passing a record allows adding more context later without new overloads.
  • setDynamicContentHandler(SerializablePredicate) and getDynamicContentHandler() are deprecated for removal in favor of the provider. Their behavior is unchanged. Setting a handler and setting a provider replace each other.
  • The grid connector now includes the column's internal id in the context menu before-open detail.

Test summary

  • Unit tests: the provider receives the clicked item and column, and null for non-application columns; handler and provider replace each other.
  • Connector test: before-open detail includes the internal column id.
  • Integration test: menu contents differ depending on the right-clicked column in a real browser.

API Changes

// com.vaadin.flow.component.grid.contextmenu.GridContextMenu
// Added
public record DynamicContentContext<T>(T item, Grid.Column<T> column) implements Serializable
public SerializablePredicate<DynamicContentContext<T>> getDynamicContentProvider()
public void setDynamicContentProvider(SerializablePredicate<DynamicContentContext<T>> dynamicContentProvider)

// Changed
- public SerializablePredicate<T> getDynamicContentHandler()
+ @Deprecated(since = "25.4", forRemoval = true) public SerializablePredicate<T> getDynamicContentHandler()
- public void setDynamicContentHandler(SerializablePredicate<T> dynamicContentHandler)
+ @Deprecated(since = "25.4", forRemoval = true) public void setDynamicContentHandler(SerializablePredicate<T> dynamicContentHandler)

Fixes #2258

🤖 Generated with Claude Code

totally-not-ai Bot and others added 2 commits October 3, 2026 06:18
…ntent handler

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a GridContextMenu#setDynamicContentHandler overload whose callback
receives both the clicked item and the clicked column. Also update the
context menu target item and column before running the dynamic content
handler, so that they are no longer one click behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
totally-not-ai Bot and others added 2 commits October 4, 2026 05:43
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Artur-
Artur- marked this pull request as ready for review October 4, 2026 06:08

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 1 comment.

Finding
📐 New setter has no getter, and the only existing getter is deprecated for removal

totally-not-ai Bot and others added 3 commits October 4, 2026 06:17
…andler

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…provider

Replace the (item, column) setDynamicContentHandler overload with
setDynamicContentProvider, which receives a DynamicContentContext record.
New context information can then be added later without new overloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@totally-not-ai totally-not-ai Bot changed the title feat: pass clicked column to grid context menu dynamic content handler feat: pass clicked column to grid context menu dynamic content provider Oct 4, 2026
totally-not-ai Bot and others added 2 commits October 5, 2026 07:53
… content handler

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Oct 5, 2026

Copy link
Copy Markdown

@sissbruecker
sissbruecker added this pull request to the merge queue Oct 5, 2026
Merged via the queue into main with commit 8a42cc1 Oct 5, 2026
21 checks passed
@sissbruecker
sissbruecker deleted the fix/grid-context-menu-dynamic-handler-column branch October 5, 2026 10:10
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 25.4.0-alpha3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GridContextMenu dynamicContentHandler called before _contextMenuTargetColumnId is set by Grid.updateContextMenuTargetItem

4 participants