diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2020-05-05 13:12:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-05 13:12:21 +0300 |
commit | bd007c1cdb0ceb0a5ba73f4184154b2f0af7c0bf (patch) | |
tree | 4124615974433c7026787a18d69450d73ba45e6b | |
parent | 37e0d4de76aa0fd36fc5631acbc06ea80ac28928 (diff) | |
download | vaadin-framework-bd007c1cdb0ceb0a5ba73f4184154b2f0af7c0bf.tar.gz vaadin-framework-bd007c1cdb0ceb0a5ba73f4184154b2f0af7c0bf.zip |
Take overlays into account in getConnectorForElement. (#11980) (#11983)
* Take overlays into account in getConnectorForElement. (#11980)
Fixes #11212
3 files changed, 217 insertions, 7 deletions
diff --git a/client/src/main/java/com/vaadin/client/Util.java b/client/src/main/java/com/vaadin/client/Util.java index 02c21179bf..02c545f563 100644 --- a/client/src/main/java/com/vaadin/client/Util.java +++ b/client/src/main/java/com/vaadin/client/Util.java @@ -579,15 +579,10 @@ public class Util { } 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(); @@ -606,6 +601,28 @@ public class Util { } } + 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. * diff --git a/uitest/src/main/java/com/vaadin/tests/tooltip/NestedOverlayTooltip.java b/uitest/src/main/java/com/vaadin/tests/tooltip/NestedOverlayTooltip.java new file mode 100644 index 0000000000..9dd23e8dd4 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/tooltip/NestedOverlayTooltip.java @@ -0,0 +1,120 @@ +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; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/tooltip/NestedOverlayTooltipTest.java b/uitest/src/test/java/com/vaadin/tests/tooltip/NestedOverlayTooltipTest.java new file mode 100644 index 0000000000..c8c5bc1eac --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/tooltip/NestedOverlayTooltipTest.java @@ -0,0 +1,73 @@ +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"); + } + +} |