summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnastasia Smirnova <anasmi@utu.fi>2018-05-03 13:07:29 +0300
committerIlia Motornyi <elmot@vaadin.com>2018-05-03 13:07:29 +0300
commitd65325e326f40e6e9abd3b7f62493e3314e788b5 (patch)
tree8a46ace98f3a1f7ce6290f98a3e7d2085830c62e
parent1d6002baf96ec0cc4cb6aff7336af8fa94f57c63 (diff)
downloadvaadin-framework-d65325e326f40e6e9abd3b7f62493e3314e788b5.tar.gz
vaadin-framework-d65325e326f40e6e9abd3b7f62493e3314e788b5.zip
Allow focus to another component, when closing the window (#10860)
Resolves #5891
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VWindow.java16
-rw-r--r--uitest/src/main/java/com/vaadin/tests/FocusOutsideWindow.java5
-rw-r--r--uitest/src/test/java/com/vaadin/tests/FocusOutsideWindowTest.java1
3 files changed, 15 insertions, 7 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VWindow.java b/client/src/main/java/com/vaadin/client/ui/VWindow.java
index c0b3f69289..f7fc2ba6b8 100644
--- a/client/src/main/java/com/vaadin/client/ui/VWindow.java
+++ b/client/src/main/java/com/vaadin/client/ui/VWindow.java
@@ -253,11 +253,16 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner,
* Restores the previously stored focused element.
*
* When the focus was changed outside the window while the window was
- * open, the originally stored element is restored.
+ * open, the originally stored element is not restored.
+ *
+ * IE returns null and other browsers HTMLBodyElement, if no element is
+ * focused after window is closed.
*/
- getApplicationConnection().getUIConnector().getWidget()
- .focusStoredElement();
-
+ if (WidgetUtil.getFocusedElement() == null || "body".equalsIgnoreCase(
+ WidgetUtil.getFocusedElement().getTagName())) {
+ getApplicationConnection().getUIConnector().getWidget()
+ .focusStoredElement();
+ }
removeTabBlockHandlers();
// If you click while the window is being closed,
// a new dragging curtain might be added and will
@@ -725,8 +730,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner,
hideDraggingCurtain();
hideResizingCurtain();
}
- super.hide(false, true, false);
-
+ super.hide();
int curIndex = getWindowOrder();
// Remove window from windowOrder to avoid references being left
// hanging.
diff --git a/uitest/src/main/java/com/vaadin/tests/FocusOutsideWindow.java b/uitest/src/main/java/com/vaadin/tests/FocusOutsideWindow.java
index d86c25a171..26fe97f2bd 100644
--- a/uitest/src/main/java/com/vaadin/tests/FocusOutsideWindow.java
+++ b/uitest/src/main/java/com/vaadin/tests/FocusOutsideWindow.java
@@ -1,11 +1,14 @@
package com.vaadin.tests;
+import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;
+@Widgetset("com.vaadin.DefaultWidgetSet")
public class FocusOutsideWindow extends AbstractTestUI {
private boolean focusTextF = true;
@@ -23,8 +26,8 @@ public class FocusOutsideWindow extends AbstractTestUI {
button.addClickListener(new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
Window window = new Window("WINDOW");
+ window.setContent(new Label("Inside window"));
window.setHeight("100px");
- // window.setModal(true);
window.addCloseListener(new Window.CloseListener() {
@Override
public void windowClose(Window.CloseEvent e) {
diff --git a/uitest/src/test/java/com/vaadin/tests/FocusOutsideWindowTest.java b/uitest/src/test/java/com/vaadin/tests/FocusOutsideWindowTest.java
index c87a356922..07dfffb6dc 100644
--- a/uitest/src/test/java/com/vaadin/tests/FocusOutsideWindowTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/FocusOutsideWindowTest.java
@@ -26,6 +26,7 @@ public class FocusOutsideWindowTest extends MultiBrowserTest {
focusBut.click();
openW.click();
$(WindowElement.class).first().close();
+ Thread.sleep(150);
assertEquals(openW, getFocusedElement());
}
}