]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make modal window block shortcuts for underlying components (#20366)
authorArtur Signell <artur@vaadin.com>
Mon, 10 Oct 2016 19:43:03 +0000 (22:43 +0300)
committerArtur Signell <artur@vaadin.com>
Mon, 24 Oct 2016 15:54:09 +0000 (18:54 +0300)
Change-Id: Ibb3b52b652d77a1bfa786417b1c92fd0a578035f

client/src/main/java/com/vaadin/client/ui/VWindow.java
client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java
uitest/src/test/java/com/vaadin/tests/components/ui/WindowAndUIShortcutsTest.java

index 008ea4ef83ed50615165c832116a95d64431ce28..da47b9381f3bfd321ce7547b1daf0b8d9adc0558 100644 (file)
@@ -1516,4 +1516,15 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner,
         return addHandler(handler, WindowMoveEvent.getType());
     }
 
+    /**
+     * Checks if a modal window is currently open.
+     * 
+     * @return <code>true</code> if a modal window is open, <code>false</code>
+     *         otherwise.
+     */
+    public static boolean isModalWindowOpen() {
+        return Document.get().getBody()
+                .hasClassName(MODAL_WINDOW_OPEN_CLASSNAME);
+    }
+
 }
index d94f030d26d02b8ac3041cf99bef56dcdb1dbb2e..c31fcb9ed6203fb5d6d6aef430b625b1d51cb5a4 100644 (file)
@@ -506,6 +506,9 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
         shortcutContextWidget.addDomHandler(new KeyDownHandler() {
             @Override
             public void onKeyDown(KeyDownEvent event) {
+                if (VWindow.isModalWindowOpen()) {
+                    return;
+                }
                 if (getWidget().actionHandler != null) {
                     Element target = Element
                             .as(event.getNativeEvent().getEventTarget());
index ba82806cacce9481f72062ff74ff404caa499032..76cc0ee807c2d2134e4e00743165418af5bfcdb4 100644 (file)
@@ -17,7 +17,9 @@ package com.vaadin.tests.components.ui;
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.openqa.selenium.By;
 import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
 
 import com.vaadin.testbench.elements.ButtonElement;
 import com.vaadin.testbench.elements.TextFieldElement;
@@ -41,4 +43,19 @@ public class WindowAndUIShortcutsTest extends SingleBrowserTest {
         Assert.assertTrue(
                 $(ButtonElement.class).caption("Close page").exists());
     }
+
+    @Test
+    public void modalCurtainShouldNotTriggerShortcuts() {
+        openTestURL();
+        $(ButtonElement.class).caption("Show page").first().click();
+        $(ButtonElement.class).caption("Open dialog window").first().click();
+
+        WebElement curtain = findElement(
+                By.className("v-window-modalitycurtain"));
+        curtain.sendKeys(Keys.ESCAPE);
+        // "Close page" should not have been clicked
+        Assert.assertTrue(
+                $(ButtonElement.class).caption("Close page").exists());
+
+    }
 }