diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-08-18 15:39:44 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-08-18 15:39:44 +0300 |
commit | 554f39ad0455623fbb1befc4444e67c809de5c0a (patch) | |
tree | 96ba4702a3ee82031808c15386c530e51f08e0b2 | |
parent | c46678460325f399c75cd8f00ceb230625524f10 (diff) | |
download | vaadin-framework-554f39ad0455623fbb1befc4444e67c809de5c0a.tar.gz vaadin-framework-554f39ad0455623fbb1befc4444e67c809de5c0a.zip |
Fix focus when Grid editor is saved or cancelled (#9835)
Fixes #9832
4 files changed, 54 insertions, 12 deletions
diff --git a/client/src/main/java/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java b/client/src/main/java/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java index 8a6a5e59e2..b7059c035f 100644 --- a/client/src/main/java/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java +++ b/client/src/main/java/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java @@ -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; } diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index 9f70a63f5e..267dbccc87 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -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); } } }; diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorBufferedTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorBufferedTest.java index d6ee3e16a0..288000ff22 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorBufferedTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorBufferedTest.java @@ -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")); + } } diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java index fdf1b9bba9..bd8d0d1ea9 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java @@ -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(); } |