Skip to content

feat!: add tooltip APIs to context-menu and menu-bar items#9223

Open
vursen wants to merge 15 commits intomainfrom
feat/menu-tooltip-apis
Open

feat!: add tooltip APIs to context-menu and menu-bar items#9223
vursen wants to merge 15 commits intomainfrom
feat/menu-tooltip-apis

Conversation

@vursen
Copy link
Copy Markdown
Contributor

@vursen vursen commented Apr 30, 2026

Adds Flow APIs for menu item tooltips, building on web-component support added in vaadin/web-components#11549.

A single <vaadin-tooltip> is slotted into the menu/context-menu and auto-attached on first use, shared across root and sub-menu items. The menu-bar connector recurses through the item tree so tooltip and tooltipPosition reach nested items, which the web component's tooltip controller picks up.

Warning

New tooltip-aware addItem overloads may make existing call sites ambiguous when a null listener is passed with a cast, e.g.:

foo.getSubMenu().addItem("bar",
        (ComponentEventListener<GridContextMenuItemClickEvent<Object>>) null);

Such call sites need to be updated to disambiguate the overload.

Fixes vaadin/web-components#10415


🤖 Generated with Claude Code

vursen and others added 2 commits May 4, 2026 10:35
Adds setTooltipText and setTooltipPosition for menu items based on
upcoming web-components support (vaadin/web-components#11549).

- ContextMenuBase gains setTooltipText / setTooltipPosition; the
  slotted <vaadin-tooltip> is auto-attached on first use and shared by
  root and sub-menu items.
- MenuBar gains setTooltipPosition, and existing setTooltipText now
  also targets sub-menu items.
- Connectors propagate tooltip and tooltipPosition for every item in
  the tree (recursively for menu-bar) so the web component's tooltip
  controller sees the values.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move `setTooltipText` and `setTooltipPosition` from `ContextMenuBase` and
`MenuBar` onto `MenuItemBase` so tooltips are configured directly on items.
Add matching `addItem(..., tooltipText)` overloads on `ContextMenuBase` and
`SubMenu` for parity with `MenuBar`. Wire `MenuBarItem` to delegate tooltip
element setup and updates back to its owning `MenuBar`.

Expand integration tests to cover root and sub-menu items, tooltip position
overrides, tooltip updates, and detach/attach cycles. Enable
`accessibleDisabledMenuItems` and `accessibleDisabledButtons` feature flags
in IT modules so disabled items still receive hover tooltips.
@vursen vursen force-pushed the feat/menu-tooltip-apis branch from c02f595 to 7c6ab85 Compare May 4, 2026 06:35
vursen and others added 7 commits May 4, 2026 10:36
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Restore deprecated MenuBar.setTooltipText(MenuItem, String) delegating to
  MenuItem.setTooltipText for source compatibility with #5294 era callers.
- Route MenuBarItem tooltip updates through resetContent so the items tree
  is fully regenerated; generateItemsTree in contextMenuConnector already
  copies tooltip and tooltipPosition recursively, so the manual
  refreshTooltips walk in menubarConnector is dropped.
- Revert menuItemsArrayGenerator field in ContextMenuBase to private; the
  package-private leftover from an earlier draft is no longer needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Trim implementation details from setTooltipText / setTooltipPosition
javadoc on MenuItemBase.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vaadin vaadin deleted a comment from github-actions Bot May 4, 2026
vursen and others added 5 commits May 4, 2026 12:30
Add (text|component, tooltipText) and (text|component, tooltipText, listener)
overloads on MenuManager so ContextMenuBase, SubMenu and MenuBar all delegate
to a single implementation.

Replace the package-private scheduleTooltipUpdate hooks on ContextMenuBase
and MenuItemBase with the existing contentReset SerializableRunnable, which
runs the same generate/reset path. MenuItemBase now stores contentReset and
calls it directly from setTooltipText / setTooltipPosition. MenuBarItem no
longer needs its scheduleTooltipUpdate override.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vursen vursen changed the title feat: add tooltip APIs to context-menu and menu-bar items feat!: add tooltip APIs to context-menu and menu-bar items May 4, 2026
Making ensureTooltipElement abstract broke GridMenuItem, which has no
override of its own. The default implementation that delegates to
contextMenu works for both grid and context-menu items; MenuBarItem
keeps its own override.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

});
updateTooltips.setId("update-tooltips");

add(attach, detach, updateTooltips, target, contextMenu);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I think we usually don't add contextMenu, it should work without it.

items.get(2).hover();
Assert.assertEquals("Item 2 / Tooltip", contextMenuTooltip.getText());
Assert.assertEquals("top",
contextMenuTooltip.getDomProperty("_position"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we could avoid checking the internal property. Not a blocker though.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[context-menu] Implement accessible disabled menu items with tooltip support

2 participants