summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMarkus Koivisto <markus@vaadin.com>2014-04-24 16:54:03 +0300
committerVaadin Code Review <review@vaadin.com>2014-04-25 14:10:24 +0000
commit6a67b0bf605ed1a17de48f3b355df398ed89a551 (patch)
treec2a39bb60af1f218a63c32da97775163486e079a /client
parentf70a5674d99321fe173dddade28f7d913b9ac32c (diff)
downloadvaadin-framework-6a67b0bf605ed1a17de48f3b355df398ed89a551.tar.gz
vaadin-framework-6a67b0bf605ed1a17de48f3b355df398ed89a551.zip
Fix TextArea with enter keyboard shortcut (#12424)
When a keyboardshortcut has been added to anywhere on the page, the previous behaviour would cause the keyboardshortcut event to be processeed before the newline was processed. The end result was that newlines were never added when typing in the TextArea. Keyboard shortcuts operate on KeyDown events. By adding a listener for these events and stopping their propagation when the ENTER key is pressed, this unwanted behaviour can be averted, and the user can enter multi-line text in a TextArea even when Enter is used as a keyboard shortcut. Obviously, this means that the keyboard shortcut will not work as long as the TextArea widget has focus. This is the new intended behaviour. Change-Id: Ied438acb8589df498e5634271e486517bf6ac41e
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/VTextArea.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java
index 5150ab2544..e6a3aa2a09 100644
--- a/client/src/com/vaadin/client/ui/VTextArea.java
+++ b/client/src/com/vaadin/client/ui/VTextArea.java
@@ -23,7 +23,9 @@ import com.google.gwt.dom.client.Style.WhiteSpace;
import com.google.gwt.dom.client.TextAreaElement;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
+import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
+import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.Command;
@@ -43,14 +45,21 @@ import com.vaadin.client.ui.dd.VDragCloneAware;
*
*/
public class VTextArea extends VTextField implements VDragCloneAware {
+
public static final String CLASSNAME = "v-textarea";
private boolean wordwrap = true;
private MaxLengthHandler maxLengthHandler = new MaxLengthHandler();
private boolean browserSupportsMaxLengthAttribute = browserSupportsMaxLengthAttribute();
+ private EnterDownHandler enterDownHandler = new EnterDownHandler();
public VTextArea() {
super(DOM.createTextArea());
setStyleName(CLASSNAME);
+
+ // KeyDownHandler is needed for correct text input on all
+ // browsers, not just those that don't support a max length attribute
+ addKeyDownHandler(enterDownHandler);
+
if (!browserSupportsMaxLengthAttribute) {
addKeyUpHandler(maxLengthHandler);
addChangeHandler(maxLengthHandler);
@@ -249,6 +258,20 @@ public class VTextArea extends VTextField implements VDragCloneAware {
}
}
+ private class EnterDownHandler implements KeyDownHandler {
+
+ @Override
+ public void onKeyDown(KeyDownEvent event) {
+ // Fix for #12424 - if the key being pressed is enter, we stop
+ // propagation of the KeyDownEvents. This prevents shortcuts that
+ // are bound to the enter key from being processed.
+ if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
+ event.stopPropagation();
+ }
+ }
+
+ }
+
@Override
public int getCursorPos() {
// This is needed so that TextBoxImplIE6 is used to return the correct
@@ -294,6 +317,7 @@ public class VTextArea extends VTextField implements VDragCloneAware {
// Overridden to avoid submitting TextArea value on enter in IE. This is
// another reason why widgets should inherit a common abstract
// class instead of directly each other.
+ // This method is overridden only for IE and Firefox.
}
@Override