diff options
author | Aleksi Hietanen <aleksi@vaadin.com> | 2016-08-19 13:02:43 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-08-23 05:45:59 +0000 |
commit | 628adbf01ae5161e0ee39e19be3d3b405b497d6e (patch) | |
tree | 24f9d33a510e16c3025c70930bff38b774b2276c | |
parent | 7daee066ae8b69ead326f6caccd17d6f0bfd9462 (diff) | |
download | vaadin-framework-628adbf01ae5161e0ee39e19be3d3b405b497d6e.tar.gz vaadin-framework-628adbf01ae5161e0ee39e19be3d3b405b497d6e.zip |
Fix TextField and related tests
- Fixes sendValueChange in TextFieldConnector
- VTextField now adds/removes dependent stylename "focus" on focus/blur
Change-Id: I965c30dd296cdab43ee5dc6cc8c7f8306392d8a2
5 files changed, 25 insertions, 8 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VTextField.java b/client/src/main/java/com/vaadin/client/ui/VTextField.java index 71453e363f..a1ef816d1d 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTextField.java +++ b/client/src/main/java/com/vaadin/client/ui/VTextField.java @@ -17,6 +17,10 @@ package com.vaadin.client.ui; import com.google.gwt.dom.client.Element; +import com.google.gwt.event.dom.client.BlurEvent; +import com.google.gwt.event.dom.client.BlurHandler; +import com.google.gwt.event.dom.client.FocusEvent; +import com.google.gwt.event.dom.client.FocusHandler; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.ui.TextBoxBase; @@ -26,18 +30,21 @@ import com.google.gwt.user.client.ui.TextBoxBase; * @author Vaadin Ltd. * */ -public class VTextField extends TextBoxBase implements Field { +public class VTextField extends TextBoxBase + implements Field, FocusHandler, BlurHandler { public static final String CLASSNAME = "v-textfield"; + public static final String CLASSNAME_FOCUS = "focus"; public VTextField() { this(DOM.createInputText()); - setStyleName(CLASSNAME); } protected VTextField(Element node) { super(node); setStyleName(CLASSNAME); + addFocusHandler(this); + addBlurHandler(this); } public void setMaxLength(int maxLength) { @@ -55,4 +62,14 @@ public class VTextField extends TextBoxBase implements Field { getElement().removeAttribute("placeholder"); } } + + @Override + public void onBlur(BlurEvent event) { + removeStyleDependentName(CLASSNAME_FOCUS); + } + + @Override + public void onFocus(FocusEvent event) { + addStyleDependentName(CLASSNAME_FOCUS); + } } diff --git a/client/src/main/java/com/vaadin/client/ui/textfield/TextFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/textfield/TextFieldConnector.java index c900b41890..794160beec 100644 --- a/client/src/main/java/com/vaadin/client/ui/textfield/TextFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/textfield/TextFieldConnector.java @@ -149,5 +149,7 @@ public class TextFieldConnector extends AbstractComponentConnector { } getRpcProxy(TextFieldServerRpc.class).setText(getWidget().getValue(), getWidget().getCursorPos()); + getState().text = getWidget().getValue(); + getState().cursorPosition = getWidget().getCursorPos(); } } diff --git a/uitest/src/main/java/com/vaadin/tests/layouts/RelativeSizeInUndefinedCssLayout.java b/uitest/src/main/java/com/vaadin/tests/layouts/RelativeSizeInUndefinedCssLayout.java index 349c709228..22cf7a3b83 100644 --- a/uitest/src/main/java/com/vaadin/tests/layouts/RelativeSizeInUndefinedCssLayout.java +++ b/uitest/src/main/java/com/vaadin/tests/layouts/RelativeSizeInUndefinedCssLayout.java @@ -19,7 +19,7 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.CssLayout; import com.vaadin.ui.FormLayout; -import com.vaadin.v7.ui.TextField; +import com.vaadin.ui.TextField; public class RelativeSizeInUndefinedCssLayout extends AbstractTestUI { @@ -40,7 +40,6 @@ public class RelativeSizeInUndefinedCssLayout extends AbstractTestUI { TextField tf = new TextField("Enter something"); tf.setWidth("100%"); formLayout.addComponent(tf); - } } diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridThemeUITest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridThemeUITest.java index 977b304665..0762533074 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridThemeUITest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridThemeUITest.java @@ -24,12 +24,12 @@ import org.openqa.selenium.interactions.Actions; import com.vaadin.testbench.elements.ButtonElement; import com.vaadin.testbench.elements.GridElement.GridCellElement; import com.vaadin.testbench.elements.GridElement.GridEditorElement; -import com.vaadin.testbench.elements.TextFieldElement; import com.vaadin.testbench.parallel.TestCategory; import com.vaadin.tests.tb3.MultiBrowserThemeTest; import com.vaadin.v7.testbench.customelements.DateFieldElement; import com.vaadin.v7.testbench.customelements.GridElement; import com.vaadin.v7.testbench.customelements.NativeSelectElement; +import com.vaadin.v7.testbench.customelements.TextFieldElement; @TestCategory("grid") public class GridThemeUITest extends MultiBrowserThemeTest { diff --git a/uitest/src/test/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPositionTest.java b/uitest/src/test/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPositionTest.java index e688a313d3..8a036787f0 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPositionTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/textfield/InputPromptAndCursorPositionTest.java @@ -17,14 +17,13 @@ public class InputPromptAndCursorPositionTest extends MultiBrowserTest { // Clear the current value and reveal the input prompt. TextFieldElement textFieldElement = $(TextFieldElement.class).get(0); - textFieldElement.setValue(""); + textFieldElement.clear(); // Update cursor position. $(ButtonElement.class).get(0).click(); // The cursor position should now be zero (not the input prompt length). LabelElement cursorPosLabel = $(LabelElement.class).get(1); - assertEquals(cursorPosLabel.getText(), "Cursor position: 0"); + assertEquals("Cursor position: 0", cursorPosLabel.getText()); } - } |