diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2020-01-15 17:07:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-15 17:07:14 +0200 |
commit | 2bf0b02220ea96ee959b766a32bf1a79ae968317 (patch) | |
tree | 96ac048aaf9af90eaf0021706e1403c2f324e1f0 /client | |
parent | a799444d832a82c3ad1467a6a60735aab015c87f (diff) | |
download | vaadin-framework-2bf0b02220ea96ee959b766a32bf1a79ae968317.tar.gz vaadin-framework-2bf0b02220ea96ee959b766a32bf1a79ae968317.zip |
Ensure value change happens before shortcuts in compatibility components (#11871)
Fixes #10854
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java b/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java index 7499779352..1c03a2719d 100644 --- a/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java +++ b/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java @@ -126,15 +126,31 @@ public class ShortcutActionHandler { target = Util.findPaintable(client, et); } final ComponentConnector finalTarget = target; - event.preventDefault(); - /* * The focused component might have unpublished changes, try to * synchronize them before firing shortcut action. */ client.flushActiveConnector(); - + /* + * Legacy components don't have built-in logic for flushing, they need a + * workaround with blur and focus to trigger the value change. + */ + ComponentConnector activeConnector = getActiveConnector(client); + if (activeConnector != null) { + Class<?> clz = activeConnector.getClass(); + while (clz != null) { + if (clz.getName().equals( + "com.vaadin.v7.client.ui.AbstractLegacyComponentConnector")) { + shakeTarget(et); + Scheduler.get().scheduleDeferred(() -> { + shakeTarget(et); + }); + break; + } + clz = clz.getSuperclass(); + } + } Scheduler.get().scheduleDeferred(() -> { if (finalTarget != null) { client.updateVariable(paintableId, "actiontarget", finalTarget, @@ -144,6 +160,26 @@ public class ShortcutActionHandler { }); } + /** + * We try to fire value change in the component the key combination was + * typed. E.g. TextField may contain newly typed text that is expected to be + * sent to server before the shortcut action is triggered. This is done by + * removing focus and then returning it immediately back to target element. + * <p> + * This is a hack copied over from V7 in order to keep the compatibility + * classes working. Main V8 classes don't require shaking. + */ + private static void shakeTarget(final Element e) { + blur(e); + focus(e); + } + + private static native ComponentConnector getActiveConnector( + ApplicationConnection ac) + /*-{ + return ac.@com.vaadin.client.ApplicationConnection::getActiveConnector()(); + }-*/; + private static native void blur(Element e) /*-{ if (e.blur) { |