Search code examples
labeltextfieldword-wrapvaadin23

How to wrap a label to the textfield in Vaadin


In my Vaadin application I have a short integer field with a long label.

TextField pubYear = new TextField("Publishing Year);
pubYear.setWidth("60px");

I do need to keep this size of the field to fit into the form, but label is cut to "Publ...". Can I do something to wrap the label text. I have plenty of vertical room, but horizontal space is very limited.


Solution

  • In Vaadin 23 the label element is in light DOM, so you can use regular global CSS like

    vaadin-text-field > label {
      overflow-wrap: break-word;
      white-space: break-spaces;
    }