}
if (connector != null) {
- // check that inside the rootElement
- while (browseElement != null && browseElement != rootElement) {
- browseElement = browseElement.getParentElement();
- }
- if (browseElement != rootElement) {
- return null;
- } else {
+ if (isConnectedToParent(browseElement, rootElement)) {
return connector;
}
+ return null;
}
browseElement = browseElement.getParentElement();
}
}
+ private static boolean isConnectedToParent(Element element,
+ Element rootElement) {
+ Element browseElement = element;
+ // check if inside the rootElement
+ while (browseElement != null && browseElement != rootElement) {
+ browseElement = browseElement.getParentElement();
+ }
+ if (browseElement == rootElement) {
+ return true;
+ }
+ // Not inside the root, possibly inside a VOverlay such as
+ // VWindow instead.
+ @SuppressWarnings("deprecation")
+ VOverlay overlay = WidgetUtil.findWidget(element, VOverlay.class,
+ false);
+ if (overlay != null && overlay.getOwner() != null) {
+ browseElement = overlay.getOwner().getElement();
+ return isConnectedToParent(browseElement, rootElement);
+ }
+ return false;
+ }
+
/**
* Will (attempt) to focus the given DOM Element.
*
--- /dev/null
+package com.vaadin.tests.tooltip;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.MenuBar;
+import com.vaadin.ui.MenuBar.MenuItem;
+import com.vaadin.ui.PopupView;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+public class NestedOverlayTooltip extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Button openWindowButton = createOpenWindowButton();
+ PopupView openPopUpViewLink = createOpenPopUpViewButton();
+
+ MenuBar menuBar = new MenuBar();
+ MenuItem menuItem = menuBar.addItem("First item");
+ MenuItem firstDropdownItem = menuItem.addItem("Dropdown item");
+ firstDropdownItem.setDescription("Dropdown Item tooltip");
+
+ addComponents(openWindowButton, openPopUpViewLink, menuBar);
+ }
+
+ private Button createOpenWindowButton() {
+ Button openWindowButton = new Button("Open window");
+ openWindowButton.setDescription("Button tooltip");
+ openWindowButton.addClickListener(event -> {
+ Window window = new Window();
+ window.center();
+ window.setWidth("500px");
+ window.setHeight("500px");
+
+ Button openInnerWindowButton = new Button("Open inner window");
+ openInnerWindowButton.setDescription("Button tooltip");
+ openInnerWindowButton.addClickListener(innerEvent -> {
+ Window innerWindow = new Window();
+ innerWindow.center();
+ innerWindow.setWidth("400px");
+ innerWindow.setHeight("400px");
+
+ Button dummyButton = new Button(
+ "This button doesn't do a thing");
+ dummyButton.setDescription("DummyButton tooltip");
+
+ MenuBar innerWindowMenuBar = new MenuBar();
+ innerWindowMenuBar.setDescription("MenuBar tooltip");
+ MenuItem menuItem = innerWindowMenuBar
+ .addItem("First item in inner window");
+ MenuItem firstDropdownItem = menuItem
+ .addItem("Inner window dropdown item");
+ firstDropdownItem
+ .setDescription("Inner window dropdown item tooltip");
+
+ innerWindow.setContent(
+ new VerticalLayout(dummyButton, innerWindowMenuBar));
+ addWindow(innerWindow);
+ });
+
+ MenuBar windowMenuBar = new MenuBar();
+ windowMenuBar.setDescription("MenuBar tooltip");
+ MenuItem menuItem = windowMenuBar.addItem("First item in window");
+ MenuItem firstDropdownItem = menuItem
+ .addItem("Window dropdown item");
+ firstDropdownItem.setDescription("Window dropdown item tooltip");
+
+ window.setContent(
+ new VerticalLayout(openInnerWindowButton, windowMenuBar));
+ addWindow(window);
+ });
+ return openWindowButton;
+ }
+
+ private PopupView createOpenPopUpViewButton() {
+ PopupView dummyView = new PopupView("Open empty popupView",
+ new VerticalLayout());
+ dummyView.setDescription("This dummy popupView has no content");
+
+ MenuBar innerPopupMenuBar = new MenuBar();
+ innerPopupMenuBar.setDescription("MenuBar tooltip");
+ MenuItem innerPopupMenuItem = innerPopupMenuBar
+ .addItem("First item in inner popupView");
+ MenuItem firstDropdownInnerPopupItem = innerPopupMenuItem
+ .addItem("Inner popupView dropdown item");
+ firstDropdownInnerPopupItem
+ .setDescription("Inner popupView dropdown item tooltip");
+
+ PopupView innerView = new PopupView("Open inner popupView",
+ new VerticalLayout(dummyView, innerPopupMenuBar));
+ innerView.setDescription("This inner popupView has content");
+
+ MenuBar popupMenuBar = new MenuBar();
+ popupMenuBar.setDescription("MenuBar tooltip");
+ MenuItem popupMenuItem = popupMenuBar
+ .addItem("First item in popupView");
+ MenuItem firstDropdownPopupItem = popupMenuItem
+ .addItem("PopupView dropdown item");
+ firstDropdownPopupItem
+ .setDescription("PopupView dropdown item tooltip");
+
+ PopupView popupView = new PopupView("Open popupView",
+ new VerticalLayout(innerView, innerView, popupMenuBar));
+ popupView.setDescription("This popupView has content");
+ return popupView;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "MenuItem's tooltip should be visible even when "
+ + "the MenuBar is located within a Window, PopupView, "
+ + "or some other component that extends VOverlay";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 11212;
+ }
+}
--- /dev/null
+package com.vaadin.tests.tooltip;
+
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.PopupViewElement;
+import com.vaadin.testbench.elements.UIElement;
+import com.vaadin.testbench.elements.WindowElement;
+import com.vaadin.tests.tb3.TooltipTest;
+
+public class NestedOverlayTooltipTest extends TooltipTest {
+
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+ openTestURL();
+ }
+
+ private void openDropDownAndTestTooltip(WebElement base, String firstItem,
+ String tooltip) throws Exception {
+ WebElement menuBar = base.findElement(By.className("v-menubar"));
+ menuBar.findElement(By.vaadin("#" + firstItem)).click();
+ WebElement popup = findElement(By.className("v-menubar-popup"));
+ WebElement item = popup.findElement(By.className("v-menubar-menuitem"));
+ checkTooltip(item, tooltip);
+ }
+
+ @Test
+ public void testMenuItemTooltip() throws Exception {
+ UIElement ui = $(UIElement.class).first();
+ openDropDownAndTestTooltip(ui, "First item", "Dropdown Item tooltip");
+ }
+
+ @Test
+ public void testMenuItemTooltipWithinWindow() throws Exception {
+ $(ButtonElement.class).first().click();
+ WindowElement window = $(WindowElement.class).first();
+ openDropDownAndTestTooltip(window, "First item in window",
+ "Window dropdown item tooltip");
+ }
+
+ @Test
+ public void testMenuItemTooltipWithinNestedWindow() throws Exception {
+ $(ButtonElement.class).first().click();
+ WindowElement window = $(WindowElement.class).first();
+ window.$(ButtonElement.class).first().click();
+ WindowElement subWindow = $(WindowElement.class).get(1);
+ openDropDownAndTestTooltip(subWindow, "First item in inner window",
+ "Inner window dropdown item tooltip");
+ }
+
+ @Test
+ public void testMenuItemTooltipWithinPopupView() throws Exception {
+ $(PopupViewElement.class).first().click();
+ WebElement popup = findElement(By.className("v-popupview-popup"));
+ openDropDownAndTestTooltip(popup, "First item in popupView",
+ "PopupView dropdown item tooltip");
+ }
+
+ @Test
+ public void testMenuItemTooltipWithinNestedPopupView() throws Exception {
+ $(PopupViewElement.class).first().click();
+ WebElement popup = findElement(By.className("v-popupview-popup"));
+ popup.findElement(By.className("v-popupview")).click();
+ WebElement innerPopup = findElements(By.className("v-popupview-popup"))
+ .get(1);
+ openDropDownAndTestTooltip(innerPopup, "First item in inner popupView",
+ "Inner popupView dropdown item tooltip");
+ }
+
+}