Skip to content

Commit 773610f

Browse files
vursenclaude
andauthored
fix: propagate menu-bar item tooltip to connector items (#9216)
## Description The new `MenuBarTooltipController` in `@vaadin/menu-bar` 25.2.0-alpha9 (introduced in [vaadin/web-components#11586](vaadin/web-components#11586)) short-circuits in `setTarget` when the target's item has no `tooltip` property — it clears the target and closes the tooltip immediately. Flow's connector built items without a `tooltip` field (tooltip text was only stored on the wrapper component and read via a custom generator), so menu-bar tooltips never opened. Fix: copy `tooltip` from the wrapper component onto each item in `menubarConnector.js` so the controller's gating check recognizes the item as having a tooltip. The existing custom generator continues to read the live value from `item.component.tooltip`, so updates via `setTooltipText` still display the latest text. Verified `MenuBarTooltipIT` passes (3/3) against local `web-components` at `main`. ## Type of change - Bugfix --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 708bb13 commit 773610f

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

  • vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/main

vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/main/java/com/vaadin/flow/component/menubar/MenuBar.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -500,19 +500,11 @@ public MenuBarI18n setMoreOptions(String moreOptions) {
500500
public void setTooltipText(MenuItem item, String tooltipText) {
501501
if (!getElement().getChildren().anyMatch(
502502
child -> "tooltip".equals(child.getAttribute("slot")))) {
503-
// No <vaadin-tooltip> yet added, add one
504-
Element tooltipElement = new Element("vaadin-tooltip");
505-
506-
tooltipElement.addAttachListener(e -> {
507-
// Assigns a generator that reads the tooltip property of the
508-
// item component
509-
tooltipElement.executeJs(
510-
"this.generator = ({item}) => { return (item && item.component) ? item.component.tooltip : ''; }");
511-
});
512-
SlotUtils.addToSlot(this, "tooltip", tooltipElement);
503+
SlotUtils.addToSlot(this, "tooltip", new Element("vaadin-tooltip"));
513504
}
514505

515506
item.getElement().setProperty("tooltip", tooltipText);
507+
updateButtons();
516508
}
517509

518510
/**

vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/main/resources/META-INF/resources/frontend/menubarConnector.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ function initLazy(menubar, appId) {
7272
// Propagate disabled state from items to parent buttons
7373
item.disabled = item.component.disabled;
7474

75+
// Propagate tooltip text so the menu-bar's tooltip controller
76+
// recognizes the item as having a tooltip and shows it.
77+
item.tooltip = item.component.tooltip;
78+
7579
// Saving item to component because `_item` can be reassigned to a new value
7680
// when the component goes to the overflow menu
7781
item.component._rootItem = item;

0 commit comments

Comments
 (0)