]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix focus when Grid editor is saved or cancelled (#9835)
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>
Fri, 18 Aug 2017 12:39:44 +0000 (15:39 +0300)
committerHenri Sara <henri.sara@gmail.com>
Fri, 18 Aug 2017 12:39:44 +0000 (15:39 +0300)
Fixes #9832

client/src/main/java/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java
client/src/main/java/com/vaadin/client/widgets/Grid.java
uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorBufferedTest.java
uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java

index 8a6a5e59e23613c37a2e930b859cb1ea076f6cb6..b7059c035f4fd94f420006aad89561449f077620 100644 (file)
@@ -230,6 +230,7 @@ public class DefaultEditorEventHandler<T> implements Editor.EventHandler<T> {
 
             // Save and close.
             event.getGrid().getEditor().save();
+            FocusUtil.setFocus(event.getGrid(), true);
             return true;
         }
 
index 9f70a63f5e94298ee36f7af9f43d0677918a8af0..267dbccc87ba9ce927711654693154265a2bda36 100755 (executable)
@@ -1468,6 +1468,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
                 @Override
                 public void onClick(ClickEvent event) {
                     save();
+                    FocusUtil.setFocus(grid, true);
                 }
             });
 
@@ -1477,6 +1478,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
                 @Override
                 public void onClick(ClickEvent event) {
                     cancel();
+                    FocusUtil.setFocus(grid, true);
                 }
             });
         }
@@ -7665,12 +7667,13 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
                 event.getDomEvent().stopPropagation();
 
                 // fixes https://github.com/vaadin/framework/issues/8632
-                // don't mark the event as handled, in order for the next handler
-                // in the handler chain (HeaderDefaultRowEventHandler) to be able to
-                // receive it. This should be safe since the next handlers in the
-                // chain (RendererEventHandler and CellFocusEventHandler) do not
-                // react to header touches/clicks.
-//                event.setHandled(true);
+                // don't mark the event as handled, in order for the next
+                // handler in the handler chain (HeaderDefaultRowEventHandler)
+                // to be able to receive it. This should be safe since the next
+                // handlers in the chain (RendererEventHandler and
+                // CellFocusEventHandler) do not react to header touches/clicks.
+
+                // event.setHandled(true);
             }
         }
     };
index d6ee3e16a0f09a34f269b46b46b2e9c692d2bd33..288000ff22d27c7a47a5e9807ef7553633fc9095 100644 (file)
@@ -81,8 +81,7 @@ public class GridEditorBufferedTest extends GridEditorTest {
         new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
 
         assertEditorClosed();
-        assertEquals("100 changed",
-                getGridElement().getCell(100, 4).getText());
+        assertEquals("100 changed", getGridElement().getCell(100, 4).getText());
     }
 
     @Test
@@ -309,4 +308,44 @@ public class GridEditorBufferedTest extends GridEditorTest {
         assertEditorOpen();
         assertEquals("(2, 0)", getGridElement().getCell(2, 0).getText());
     }
+
+    @Test
+    public void testFocusWhenCancelByKeyboard() {
+        editRow(5);
+        getGridElement().getEditor().getField(0).click();
+        new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform();
+        assertTrue("Focus should be in the Grid",
+                getFocusedElement().getAttribute("class").contains("v-grid"));
+    }
+
+    @Test
+    public void testFocusWhenSaveByKeyboard() {
+        editRow(5);
+        getGridElement().getEditor().getField(0).click();
+        new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
+        assertTrue("Focus should be in the Grid",
+                getFocusedElement().getAttribute("class").contains("v-grid"));
+    }
+
+    @Test
+    public void testFocusWhenSaveByClick() {
+        editRow(5);
+
+        getGridElement().getEditor()
+                .findElement(By.className("v-grid-editor-save")).click();
+
+        assertTrue("Focus should be in the Grid",
+                getFocusedElement().getAttribute("class").contains("v-grid"));
+    }
+
+    @Test
+    public void testFocusWhenCancelByClick() {
+        editRow(5);
+
+        getGridElement().getEditor()
+                .findElement(By.className("v-grid-editor-cancel")).click();
+
+        assertTrue("Focus should be in the Grid",
+                getFocusedElement().getAttribute("class").contains("v-grid"));
+    }
 }
index fdf1b9bba955d7fe50783b41ad9f31f45835e517..bd8d0d1ea9c66c82d66905892f7f06253121bcc0 100644 (file)
@@ -77,8 +77,8 @@ public abstract class GridEditorTest extends GridBasicsTest {
     }
 
     protected void assertEditorOpen() {
-        assertTrue("Editor is supposed to be open",
-                getGridElement().isElementPresent(By.vaadin("#editor")));
+        waitUntil(driver -> getGridElement()
+                .isElementPresent(By.vaadin("#editor")));
     }
 
     protected void assertEditorClosed() {
@@ -197,12 +197,11 @@ public abstract class GridEditorTest extends GridBasicsTest {
                 editorPos == editor.getLocation().getY());
     }
 
-    @Ignore("Needs programmatic sorting")
     @Test
     public void testEditorClosedOnSort() {
         editRow(5);
 
-        selectMenuPath("Component", "State", "Sort by column", "Column 0, ASC");
+        selectMenuPath("Component", "Columns", "Column 0", "Sort ASC");
 
         assertEditorClosed();
     }