From 877d7ef7ce3e29905e55fd36ee2d3ac8cf77ccf6 Mon Sep 17 00:00:00 2001 From: Anastasia Smirnova Date: Thu, 5 Dec 2019 20:33:31 +0200 Subject: Close window on ESC, when maximized button is clicked (#11840) Fixes #11838 Changes: 1. Close a window when maximized button is focused and ESC is pressed 2. Add additional check for a close button to react to the ESC key press 3. Rename a private method `onCloseClick` to `closeWindow` to allow code re-use --- client/src/main/java/com/vaadin/client/ui/VWindow.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'client/src') 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 e19a13c005..03cb7e16bf 100644 --- a/client/src/main/java/com/vaadin/client/ui/VWindow.java +++ b/client/src/main/java/com/vaadin/client/ui/VWindow.java @@ -1014,14 +1014,20 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, // if clicked or key ENTER or SPACE is pressed } else if (isClosable() && target == closeBox) { if (type == Event.ONCLICK || (type == Event.ONKEYUP - && isKeyEnterOrSpace(event.getKeyCode()))) { - onCloseClick(); + && (isKeyEnterOrSpace(event.getKeyCode())) + || event.getKeyCode() == KeyCodes.KEY_ESCAPE)) { + closeWindow(); } bubble = false; } else if (target == maximizeRestoreBox) { + // if ESC is pressed, close the window + if (type == Event.ONKEYUP + && event.getKeyCode() == KeyCodes.KEY_ESCAPE) { + closeWindow(); + } // handled in connector // if clicked or key ENTER or SPACE is pressed - if (type != Event.ONCLICK && !(type == Event.ONKEYUP + else if (type != Event.ONCLICK && !(type == Event.ONKEYUP && isKeyEnterOrSpace(event.getKeyCode()))) { bubble = false; } @@ -1097,7 +1103,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, } } - private void onCloseClick() { + private void closeWindow() { // Send the close event to the server client.updateVariable(id, "close", true, true); } -- cgit v1.2.3