]> source.dussan.org Git - vaadin-framework.git/commitdiff
Scrolling down submenus via scrollbar (MenuBar.isAutoOpen()) (#10456)
authorAnna Miroshnik <anna.miroshnik@arcadia.spb.ru>
Thu, 30 Oct 2014 11:30:48 +0000 (14:30 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 4 Nov 2016 13:51:41 +0000 (13:51 +0000)
full name of defect: Can't scroll down submenus using the scrollbar when
MenuBar.isAutoOpen() == true
Tests.

Change-Id: I2cbe797c96dc6a780df147e165babb23f7fbdef3

client/src/main/java/com/vaadin/client/ui/VMenuBar.java
uitest/src/main/java/com/vaadin/tests/components/menubar/MenuBarIsAutoOpenScrolling.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/menubar/MenuBarIsAutoOpenScrollingTest.java [new file with mode: 0644]

index d08301ec93e4b4d187683341796f800e3f802f1e..2f1b93994b8c6d8a447779bb7f46ea6eefdfc865 100644 (file)
@@ -33,6 +33,10 @@ import com.google.gwt.event.dom.client.KeyDownEvent;
 import com.google.gwt.event.dom.client.KeyDownHandler;
 import com.google.gwt.event.dom.client.KeyPressEvent;
 import com.google.gwt.event.dom.client.KeyPressHandler;
+import com.google.gwt.event.dom.client.MouseOutEvent;
+import com.google.gwt.event.dom.client.MouseOutHandler;
+import com.google.gwt.event.dom.client.MouseOverEvent;
+import com.google.gwt.event.dom.client.MouseOverHandler;
 import com.google.gwt.event.logical.shared.CloseEvent;
 import com.google.gwt.event.logical.shared.CloseHandler;
 import com.google.gwt.user.client.Command;
@@ -54,7 +58,7 @@ import com.vaadin.shared.ui.menubar.MenuBarConstants;
 
 public class VMenuBar extends SimpleFocusablePanel
         implements CloseHandler<PopupPanel>, KeyPressHandler, KeyDownHandler,
-        FocusHandler, SubPartAware {
+        FocusHandler, SubPartAware, MouseOutHandler, MouseOverHandler {
 
     // The hierarchy of VMenuBar is a bit weird as VMenuBar is the Paintable,
     // used for the root menu but also used for the sub menus.
@@ -605,6 +609,8 @@ public class VMenuBar extends SimpleFocusablePanel
         popup.setWidget(item.getSubMenu());
         popup.addCloseHandler(this);
         popup.addAutoHidePartner(item.getElement());
+        popup.addDomHandler(this, MouseOutEvent.getType());
+        popup.addDomHandler(this, MouseOverEvent.getType());
 
         // at 0,0 because otherwise IE7 add extra scrollbars (#5547)
         popup.setPopupPosition(0, 0);
@@ -1718,4 +1724,14 @@ public class VMenuBar extends SimpleFocusablePanel
     public CustomMenuItem getMenuItemWithElement(Element element) {
         return getMenuItemWithElement(DOM.asOld(element));
     }
+
+    @Override
+    public void onMouseOver(MouseOverEvent event) {
+        LazyCloser.cancelClosing();
+    }
+
+    @Override
+    public void onMouseOut(MouseOutEvent event) {
+        LazyCloser.schedule();
+    }
 }
diff --git a/uitest/src/main/java/com/vaadin/tests/components/menubar/MenuBarIsAutoOpenScrolling.java b/uitest/src/main/java/com/vaadin/tests/components/menubar/MenuBarIsAutoOpenScrolling.java
new file mode 100644 (file)
index 0000000..d3cdaca
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2000-2014 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.tests.components.menubar;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.MenuBar;
+import com.vaadin.ui.MenuBar.MenuItem;
+
+public class MenuBarIsAutoOpenScrolling extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        MenuBar menuBar = new MenuBar();
+        menuBar.setAutoOpen(true);
+        menuBar.addStyleName("menu-bar");
+
+        MenuItem item = menuBar.addItem("Item", null);
+
+        for (int i = 1; i < 100; i++) {
+            item.addItem("SubItem" + i, null);
+        }
+
+        addComponent(menuBar);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "SubMenu (when MenuBar.isAutoOpen()) should not dissapear after a couple of seconds when the mouse pointer is over the scrollbar.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 10456;
+    }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/menubar/MenuBarIsAutoOpenScrollingTest.java b/uitest/src/test/java/com/vaadin/tests/components/menubar/MenuBarIsAutoOpenScrollingTest.java
new file mode 100644 (file)
index 0000000..51fca00
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2000-2014 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.tests.components.menubar;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+
+import com.vaadin.testbench.elements.MenuBarElement;
+import com.vaadin.testbench.parallel.Browser;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class MenuBarIsAutoOpenScrollingTest extends MultiBrowserTest {
+
+    @Override
+    public List<DesiredCapabilities> getBrowsersToTest() {
+        List<DesiredCapabilities> list = super.getBrowsersToTest();
+        // test is unreliable on Firefox
+        list.remove(Browser.FIREFOX.getDesiredCapabilities());
+        return list;
+    }
+
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testIsAutoOpenSubmenuScrolling() {
+        openTestURL();
+        Actions actions = new Actions(driver);
+
+        MenuBarElement menu = $(MenuBarElement.class).get(0);
+
+        actions.moveToElement(menu).perform();
+
+        waitForElementPresent(By.className("v-menubar-popup"));
+
+        WebElement subMenuPopup = driver
+                .findElement(By.className("v-menubar-popup"));
+
+        // here we have to use pause() because LazyCloser in VMenuBar auto
+        // closes submenus popup in 750 ms.
+        actions.moveToElement(subMenuPopup, subMenuPopup.getSize().width - 7,
+                100).clickAndHold().pause(1000).moveByOffset(0, 200).release()
+                .perform();
+
+        // subMenuPopup should still be presented
+        waitUntil(ExpectedConditions
+                .visibilityOfElementLocated(By.className("v-menubar-popup")));
+
+        actions.moveByOffset(100, 0).perform();
+        // subMenuPopup should disappear
+        waitUntil(ExpectedConditions
+                .not(ExpectedConditions.invisibilityOfElementLocated(
+                        By.className("v-menubar-popup"))));
+    }
+}