summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorOlli Tietäväinen <ollit@vaadin.com>2018-04-16 17:56:16 +0300
committerIlia Motornyi <elmot@vaadin.com>2018-04-16 17:56:16 +0300
commitd0bc2ad8f940506d2d2aa1a79725b5ed636a914b (patch)
tree2589ced7c5664a843a80bff2c15c7a52d290b080 /client
parent4dec38e73d23e09d193bec02fbd1ce8629098578 (diff)
downloadvaadin-framework-d0bc2ad8f940506d2d2aa1a79725b5ed636a914b.tar.gz
vaadin-framework-d0bc2ad8f940506d2d2aa1a79725b5ed636a914b.zip
Add a check for tab events trying to set focus outside a modal Window (#10655)
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VWindow.java26
1 files changed, 26 insertions, 0 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 69ffa8a89a..746c432997 100644
--- a/client/src/main/java/com/vaadin/client/ui/VWindow.java
+++ b/client/src/main/java/com/vaadin/client/ui/VWindow.java
@@ -178,9 +178,11 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner,
private NativePreviewHandler topEventBlocker;
private NativePreviewHandler bottomEventBlocker;
+ private NativePreviewHandler modalEventBlocker;
private HandlerRegistration topBlockerRegistration;
private HandlerRegistration bottomBlockerRegistration;
+ private HandlerRegistration modalBlockerRegistration;
// Prevents leaving the window with the Tab key when true
private boolean doTabStop;
@@ -264,6 +266,8 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner,
.addNativePreviewHandler(topEventBlocker);
bottomBlockerRegistration = Event
.addNativePreviewHandler(bottomEventBlocker);
+ modalBlockerRegistration = Event
+ .addNativePreviewHandler(modalEventBlocker);
}
}
@@ -274,6 +278,9 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner,
bottomBlockerRegistration.removeHandler();
bottomBlockerRegistration = null;
+
+ modalBlockerRegistration.removeHandler();
+ modalBlockerRegistration = null;
}
}
@@ -468,6 +475,25 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner,
nativeEvent.preventDefault();
}
};
+
+ // Handle modal window + tabbing when the focus is not inside the
+ // window (custom tab order or tabbing in from browser url bar)
+ modalEventBlocker = event -> {
+ if (!vaadinModality
+ || getElement().isOrHasChild(WidgetUtil.getFocusedElement())
+ || (getTopmostWindow() != VWindow.this)) {
+ return;
+ }
+
+ NativeEvent nativeEvent = event.getNativeEvent();
+ if (nativeEvent.getType().equals("keyup")
+ && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB) {
+ nativeEvent.preventDefault();
+ focus();
+
+ }
+ };
+
}
/**