Vaadin 14 force text uppercase in java - not html

Hi.

I am struggling to force my textfield in vaadin 14 to only be uppercase. In prev vaadin I added style to do this. But TextField now has no style method.

You can do it with styles by using @CssImport.

  1. Put a file, called e.g. custom-textfield.css, in <project-root>/frontend/styles/
  2. Put the following contents to the file:
:host(.uppercase) [part="value"]
 { // target the "value" part of elements that have the "uppercase" class name
    text-transform: uppercase;
}
  1. Import the file in your app, remember to use the themeFor = "vaadin-text-field":
@CssImport(value = "/styles/custom-textfield.css", themeFor = "vaadin-text-field")
public class MainView extends VerticalLayout {
//...
  1. add a class name to your text field that you want to have in upper case
TextField textField = new TextField("Some label");
textField.setClassName("uppercase");
  1. Read more about theming here: https://vaadin.com/docs/v14/flow/theme/theming-overview.html