Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Optional;
import java.util.function.Function;

import com.vaadin.flow.component.InputMode;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
Expand Down Expand Up @@ -383,6 +384,41 @@
return getElement().getProperty("pattern");
}

/**
* Sets the {@link InputMode} that hints at the type of virtual keyboard to
* display when the user interacts with the field on a mobile device. If not
* set, the browser defaults to {@link InputMode#TEXT}.
*
* @param inputMode
Comment thread
web-padawan marked this conversation as resolved.
* the {@code inputmode} value, or {@code null} to unset
* @see <a href=
* "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode">
* inputmode attribute</a>
* @since 25.3
*/
public void setInputMode(InputMode inputMode) {
if (inputMode == null) {
getElement().removeProperty("inputMode");

Check failure on line 401 in vaadin-text-field-flow-parent/vaadin-text-field-flow/src/main/java/com/vaadin/flow/component/textfield/TextField.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "inputMode" 3 times.

See more on https://sonarcloud.io/project/issues?id=vaadin_flow-components&issues=AZ795A-ZRZnl_-eTN1Mj&open=AZ795A-ZRZnl_-eTN1Mj&pullRequest=9614
} else {
getElement().setProperty("inputMode", inputMode.getValue());
}
}

/**
* Gets the {@link InputMode} of the field.
*
* @return the {@code inputmode} value, or {@code null} if not set
* @see #setInputMode(InputMode)
* @since 25.3
*/
public InputMode getInputMode() {
String inputMode = getElement().getProperty("inputMode");
if (inputMode == null || inputMode.isEmpty()) {
return null;
}
return InputMode.valueOf(inputMode.toUpperCase());

Check warning on line 419 in vaadin-text-field-flow-parent/vaadin-text-field-flow/src/main/java/com/vaadin/flow/component/textfield/TextField.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define the locale to be used in this String operation.

See more on https://sonarcloud.io/project/issues?id=vaadin_flow-components&issues=AZ795A-ZRZnl_-eTN1Mk&open=AZ795A-ZRZnl_-eTN1Mk&pullRequest=9614
}

@Override
public String getEmptyValue() {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.vaadin.flow.component.AbstractField;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasAriaLabel;
import com.vaadin.flow.component.InputMode;
import com.vaadin.flow.component.shared.HasAllowedCharPattern;
import com.vaadin.flow.component.shared.HasThemeVariant;
import com.vaadin.flow.component.shared.HasTooltip;
Expand Down Expand Up @@ -114,6 +115,26 @@ void autoselectPropertyValue() {
assertAutoselectPropertyValueEquals(textField, false);
}

@Test
void inputMode_defaultsToNull() {
TextField textField = new TextField();
Assertions.assertNull(textField.getInputMode());
}

@Test
void setInputMode_getInputMode() {
TextField textField = new TextField();

textField.setInputMode(InputMode.NUMERIC);
Assertions.assertEquals(InputMode.NUMERIC, textField.getInputMode());
Assertions.assertEquals("numeric",
textField.getElement().getProperty("inputMode"));

textField.setInputMode(null);
Assertions.assertNull(textField.getInputMode());
Assertions.assertNull(textField.getElement().getProperty("inputMode"));
}

@Test
void elementHasValue_wrapIntoTextField_propertyIsNotSetToInitialValue() {
ComponentFromTest
Expand Down
Loading