diff options
3 files changed, 75 insertions, 1 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 746c432997..0fffd2fed6 100644 --- a/client/src/main/java/com/vaadin/client/ui/VWindow.java +++ b/client/src/main/java/com/vaadin/client/ui/VWindow.java @@ -709,7 +709,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, hideDraggingCurtain(); hideResizingCurtain(); } - super.hide(); + super.hide(false, true, false); int curIndex = getWindowOrder(); // Remove window from windowOrder to avoid references being left diff --git a/uitest/src/main/java/com/vaadin/tests/FocusOutsideWindow.java b/uitest/src/main/java/com/vaadin/tests/FocusOutsideWindow.java new file mode 100644 index 0000000000..d86c25a171 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/FocusOutsideWindow.java @@ -0,0 +1,43 @@ +package com.vaadin.tests; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.TextField; +import com.vaadin.ui.Window; + +public class FocusOutsideWindow extends AbstractTestUI { + private boolean focusTextF = true; + + @Override + protected void setup(VaadinRequest request) { + + Button button = new Button("Open window"); + Button focusBut = new Button("Focus TextField/DefaultFocus", e -> { + focusTextF = !focusTextF; + }); + button.setId("buttonOp"); + focusBut.setId("focusBut"); + final TextField textField = new TextField("Focus shoud go here"); + + button.addClickListener(new Button.ClickListener() { + public void buttonClick(Button.ClickEvent event) { + Window window = new Window("WINDOW"); + window.setHeight("100px"); + // window.setModal(true); + window.addCloseListener(new Window.CloseListener() { + @Override + public void windowClose(Window.CloseEvent e) { + if (focusTextF) { + textField.focus(); + } + } + }); + addWindow(window); + } + }); + addComponent(button); + addComponent(focusBut); + addComponent(textField); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/FocusOutsideWindowTest.java b/uitest/src/test/java/com/vaadin/tests/FocusOutsideWindowTest.java new file mode 100644 index 0000000000..c87a356922 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/FocusOutsideWindowTest.java @@ -0,0 +1,31 @@ +package com.vaadin.tests; + +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.elements.WindowElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import static org.junit.Assert.assertEquals; + +public class FocusOutsideWindowTest extends MultiBrowserTest { + + @Test + public void verifyTextFieldFocused() throws Exception { + openTestURL(); + WebElement openW = findElement(By.id("buttonOp")); + WebElement focusBut = findElement(By.id("focusBut")); + // Closing window should focus TexField + openW.click(); + TextFieldElement textField = $(TextFieldElement.class).first(); + WindowElement window = $(WindowElement.class).first(); + window.close(); + assertEquals(textField.getWrappedElement(), getFocusedElement()); + // Closing window should focus button back(default behaviour) + focusBut.click(); + openW.click(); + $(WindowElement.class).first().close(); + assertEquals(openW, getFocusedElement()); + } +} |