-
Notifications
You must be signed in to change notification settings - Fork 78
feat!: add tooltip APIs to context-menu and menu-bar items #9223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2826eaf
7c6ab85
4d04794
88747a3
c94b54b
e2dbf92
39de9ee
622e2e3
2e70a50
059bd53
ae246e9
b34dde3
46af937
9f89ba3
48d07ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright 2000-2026 Vaadin Ltd. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package com.vaadin.flow.component.contextmenu.it; | ||
|
|
||
| import com.vaadin.flow.component.contextmenu.ContextMenu; | ||
| import com.vaadin.flow.component.html.Div; | ||
| import com.vaadin.flow.component.html.NativeButton; | ||
| import com.vaadin.flow.component.shared.Tooltip.TooltipPosition; | ||
| import com.vaadin.flow.component.shared.TooltipConfiguration; | ||
| import com.vaadin.flow.router.Route; | ||
|
|
||
| @Route("vaadin-context-menu/tooltip") | ||
| public class ContextMenuTooltipPage extends Div { | ||
|
|
||
| public ContextMenuTooltipPage() { | ||
| // Reset default delay values from 500 to 0 | ||
| TooltipConfiguration.setDefaultFocusDelay(0); | ||
| TooltipConfiguration.setDefaultHoverDelay(0); | ||
| TooltipConfiguration.setDefaultHideDelay(0); | ||
|
|
||
| var target = new NativeButton("Target"); | ||
| target.setId("target"); | ||
|
|
||
| var contextMenu = new ContextMenu(target); | ||
|
|
||
| // Root items | ||
| var item0 = contextMenu.addItem("Item 0", "Item 0 / Tooltip"); | ||
|
|
||
| var item1 = contextMenu.addItem("Item 1", "Item 1 / Tooltip"); | ||
| item1.setEnabled(false); | ||
|
|
||
| var item2 = contextMenu.addItem("Item 2", "Item 2 / Tooltip"); | ||
| item2.setTooltipPosition(TooltipPosition.TOP); | ||
|
|
||
| // Sub menu items | ||
| var item0_0 = item0.getSubMenu().addItem("Item 0-0", | ||
|
Check warning on line 49 in vaadin-context-menu-flow-parent/vaadin-context-menu-flow-integration-tests/src/main/java/com/vaadin/flow/component/contextmenu/it/ContextMenuTooltipPage.java
|
||
| "Item 0-0 / Tooltip"); | ||
|
|
||
| var item0_1 = item0.getSubMenu().addItem("Item 0-1", | ||
|
Check warning on line 52 in vaadin-context-menu-flow-parent/vaadin-context-menu-flow-integration-tests/src/main/java/com/vaadin/flow/component/contextmenu/it/ContextMenuTooltipPage.java
|
||
| "Item 0-1 / Tooltip"); | ||
| item0_1.setEnabled(false); | ||
|
|
||
| var item0_2 = item0.getSubMenu().addItem("Item 0-2", | ||
|
Check warning on line 56 in vaadin-context-menu-flow-parent/vaadin-context-menu-flow-integration-tests/src/main/java/com/vaadin/flow/component/contextmenu/it/ContextMenuTooltipPage.java
|
||
| "Item 0-2 / Tooltip"); | ||
| item0_2.setTooltipPosition(TooltipPosition.TOP); | ||
|
|
||
| var attach = new NativeButton("Attach", event -> add(target)); | ||
| attach.setId("attach"); | ||
| var detach = new NativeButton("Detach", event -> remove(target)); | ||
| detach.setId("detach"); | ||
|
|
||
| var updateTooltips = new NativeButton("Update tooltips", event -> { | ||
| item0.setTooltipText("Item 0 / Updated Tooltip"); | ||
| item0_0.setTooltipText("Item 0-0 / Updated Tooltip"); | ||
| }); | ||
| updateTooltips.setId("update-tooltips"); | ||
|
|
||
| add(attach, detach, updateTooltips, target, contextMenu); | ||
|
web-padawan marked this conversation as resolved.
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| com.vaadin.experimental.accessibleDisabledMenuItems=true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * Copyright 2000-2026 Vaadin Ltd. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package com.vaadin.flow.component.contextmenu.it; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import com.vaadin.flow.component.contextmenu.testbench.ContextMenuElement; | ||
| import com.vaadin.flow.testutil.TestPath; | ||
| import com.vaadin.testbench.TestBenchElement; | ||
| import com.vaadin.tests.AbstractComponentIT; | ||
|
|
||
| @TestPath("vaadin-context-menu/tooltip") | ||
| public class ContextMenuTooltipIT extends AbstractComponentIT { | ||
|
|
||
| private TestBenchElement target; | ||
| private ContextMenuElement contextMenu; | ||
| private TestBenchElement contextMenuTooltip; | ||
|
|
||
| @Before | ||
| public void init() { | ||
| open(); | ||
| target = $(TestBenchElement.class).id("target"); | ||
| contextMenu = $(ContextMenuElement.class).single(); | ||
| contextMenuTooltip = contextMenu.$("vaadin-tooltip").single(); | ||
| } | ||
|
|
||
| @Test | ||
| public void openMenu_hoverOverRootItems_tooltipDisplayed() { | ||
| ContextMenuElement.openByRightClick(target); | ||
|
|
||
| var items = contextMenu.getMenuItems(); | ||
|
|
||
| items.get(0).hover(); | ||
| Assert.assertEquals("Item 0 / Tooltip", contextMenuTooltip.getText()); | ||
|
|
||
| items.get(1).hover(); | ||
| Assert.assertEquals("Item 1 / Tooltip", contextMenuTooltip.getText()); | ||
|
|
||
| items.get(2).hover(); | ||
| Assert.assertEquals("Item 2 / Tooltip", contextMenuTooltip.getText()); | ||
| Assert.assertEquals("top", | ||
| contextMenuTooltip.getDomProperty("_position")); | ||
|
web-padawan marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Test | ||
| public void openMenu_hoverOverSubMenuItems_tooltipDisplayed() { | ||
| ContextMenuElement.openByRightClick(target); | ||
|
|
||
| var subMenu = contextMenu.getMenuItems().get(0).openSubMenu(); | ||
| var subMenuItems = subMenu.getMenuItems(); | ||
|
|
||
| subMenuItems.get(0).hover(); | ||
| Assert.assertEquals("Item 0-0 / Tooltip", contextMenuTooltip.getText()); | ||
|
|
||
| subMenuItems.get(1).hover(); | ||
| Assert.assertEquals("Item 0-1 / Tooltip", contextMenuTooltip.getText()); | ||
|
|
||
| subMenuItems.get(2).hover(); | ||
| Assert.assertEquals("Item 0-2 / Tooltip", contextMenuTooltip.getText()); | ||
| Assert.assertEquals("top", | ||
| contextMenuTooltip.getDomProperty("_position")); | ||
| } | ||
|
|
||
| @Test | ||
| public void updateTooltip_openMenu_hoverOverItems_updatedTooltipDisplayed() { | ||
| clickElementWithJs("update-tooltips"); | ||
|
|
||
| ContextMenuElement.openByRightClick(target); | ||
|
|
||
| contextMenu.getMenuItems().get(0).hover(); | ||
| Assert.assertEquals("Item 0 / Updated Tooltip", | ||
| contextMenuTooltip.getText()); | ||
|
|
||
| var subMenu = contextMenu.getMenuItems().get(0).openSubMenu(); | ||
| subMenu.getMenuItems().get(0).hover(); | ||
| Assert.assertEquals("Item 0-0 / Updated Tooltip", | ||
| contextMenuTooltip.getText()); | ||
| } | ||
|
|
||
| @Test | ||
| public void detachAndAttach_openMenu_hoverOverItems_tooltipDisplayed() { | ||
| detachAndAttach(); | ||
|
|
||
| ContextMenuElement.openByRightClick(target); | ||
|
|
||
| contextMenu.getMenuItems().get(0).hover(); | ||
| Assert.assertEquals("Item 0 / Tooltip", contextMenuTooltip.getText()); | ||
|
|
||
| var subMenu = contextMenu.getMenuItems().get(0).openSubMenu(); | ||
| subMenu.getMenuItems().get(0).hover(); | ||
| Assert.assertEquals("Item 0-0 / Tooltip", contextMenuTooltip.getText()); | ||
| } | ||
|
|
||
| private void detachAndAttach() { | ||
| clickElementWithJs("detach"); | ||
| clickElementWithJs("attach"); | ||
| target = $(TestBenchElement.class).id("target"); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be a web component issue but noticed this on the IT page. Somethimes the tooltip ends up behind a sub-menu:
Kapture.2026-05-04.at.16.17.47.mp4
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After detaching and reattaching the target button, it moves to the next line. As a result, the tooltip doesn't fit on the left side anymore, so it falls back to the right side and ends up under the menu perhaps because the web component opens its overlay before the sub-menu's one (not sure about that though). Either way, it's a web component issue indeed.