aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-09-07 15:08:26 +0300
committerVaadin Code Review <review@vaadin.com>2016-05-11 10:48:48 +0000
commit5d6f189e323fe551af367eff7be358e0f8ab5ff0 (patch)
tree92998af6a59012da1e64ce4ab27bb8da2fa75715
parentb784032b3b3438036f5cbaf424840698221280a8 (diff)
downloadvaadin-framework-5d6f189e323fe551af367eff7be358e0f8ab5ff0.tar.gz
vaadin-framework-5d6f189e323fe551af367eff7be358e0f8ab5ff0.zip
Always close expanded top level menu item on click (#14568).
Change-Id: I04b0b64fd9054b7284efa59a8c56d8a64616ca7b
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VMenuBar.java2
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/menubar/MenuBarClickOpenedMenu.java63
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/menubar/MenuBarClickOpenedMenuTest.java89
3 files changed, 154 insertions, 0 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VMenuBar.java b/client/src/main/java/com/vaadin/client/ui/VMenuBar.java
index b2b40c12f7..b3825d2de5 100644
--- a/client/src/main/java/com/vaadin/client/ui/VMenuBar.java
+++ b/client/src/main/java/com/vaadin/client/ui/VMenuBar.java
@@ -590,8 +590,10 @@ public class VMenuBar extends SimpleFocusablePanel implements
popup.setOwner(this);
} else {
VMenuBar parent = parentMenu;
+ popup.addAutoHidePartner(parent.getSelected().getElement());
while (parent.getParentMenu() != null) {
parent = parent.getParentMenu();
+ popup.addAutoHidePartner(parent.getSelected().getElement());
}
popup.setOwner(parent);
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/menubar/MenuBarClickOpenedMenu.java b/uitest/src/main/java/com/vaadin/tests/components/menubar/MenuBarClickOpenedMenu.java
new file mode 100644
index 0000000000..2bcbbbba3e
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/menubar/MenuBarClickOpenedMenu.java
@@ -0,0 +1,63 @@
+/*
+ * 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.Command;
+import com.vaadin.ui.MenuBar.MenuItem;
+
+/**
+ * Test UI for top click on expanded top level menu and sub-menus.
+ *
+ * @author Vaadin Ltd
+ */
+public class MenuBarClickOpenedMenu extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ MenuBar menuBar = new MenuBar();
+ menuBar.addStyleName("top-level");
+ MenuItem file = menuBar.addItem("File", null);
+ file.setStyleName("first-level");
+ MenuItem open = file.addItem("Open", null);
+ open.setStyleName("second-level");
+ MenuItem as = open.addItem("as", null);
+ as.setStyleName("third-level");
+ MenuItem leaf = as.addItem("Text", new MenuBarCommand());
+ leaf.setStyleName("leaf");
+ addComponent(menuBar);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Top level menu item should always close menu on click. "
+ + "Submenu should not close if it's already opened";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 14568;
+ }
+
+ private class MenuBarCommand implements Command {
+ @Override
+ public void menuSelected(MenuItem selectedItem) {
+ }
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/menubar/MenuBarClickOpenedMenuTest.java b/uitest/src/test/java/com/vaadin/tests/components/menubar/MenuBarClickOpenedMenuTest.java
new file mode 100644
index 0000000000..5f5e6c8abc
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/menubar/MenuBarClickOpenedMenuTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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 org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Test for top level menu item which should close its sub-menus each time when
+ * it's clicked. Also it checks sub-menu item which should not close its
+ * sub-menus if they are opened on click.
+ *
+ * @author Vaadin Ltd
+ */
+public class MenuBarClickOpenedMenuTest extends MultiBrowserTest {
+
+ @Before
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+ openTestURL();
+ expand("v-menubar-menuitem-first-level");
+ expand("v-menubar-menuitem-second-level");
+ expand("v-menubar-menuitem-third-level");
+ checkPresence("v-menubar-menuitem-leaf", true);
+ }
+
+ @Test
+ public void testTopLevelMenuClickClosesSubMenus() {
+ click("v-menubar-menuitem-first-level");
+ checkSubMenus(false);
+ }
+
+ @Test
+ public void testSubMenuClickDoesNotCloseSubMenus() {
+ click("v-menubar-menuitem-second-level");
+ checkSubMenus(true);
+ }
+
+ private void expand(String menuItemClassName) {
+ checkPresence(menuItemClassName, true);
+ click(menuItemClassName);
+ }
+
+ private void click(String menuItemClassName) {
+ findElement(By.className(menuItemClassName)).click();
+ }
+
+ private void checkSubMenus(boolean present) {
+ checkPresence("v-menubar-menuitem-second-level", present);
+ checkPresence("v-menubar-menuitem-third-level", present);
+ checkPresence("v-menubar-menuitem-leaf", present);
+ }
+
+ private void checkPresence(final String menuItemClassName,
+ final boolean present) {
+ waitUntil(new ExpectedCondition<Boolean>() {
+ @Override
+ public Boolean apply(WebDriver input) {
+ return isElementPresent(By.className(menuItemClassName)) == present;
+ }
+
+ @Override
+ public String toString() {
+ // Timed out after 10 seconds waiting for ...
+ return menuItemClassName + " to " + (present ? "" : "not ")
+ + "be present";
+ }
+ });
+ }
+}