In Vaadin 8 the width of an input was the maximum of label length and the length of the actual input. Nowadays the total length is always the length of the input, and if the label is longer it will be shortened with an ellipsis.
Example from Vaadin 8 app:
Same app, but now with Vaadin 24:
How can I adjust the style so that it looks like before?
But how do I set the width at runtime? Not all inputs habe the same length, of course.
I tried with a utility method which uses the Element API to access the label and the input slot and set individual width attributes, but it doesn’t work quite yet.
Those elements have no representation on the server side. If you want to make it dynamic, then I’d suggest to use a CSS variable for setting the input width, and then change that CSS variable per field instance.
.custom-width-container::part(input-field), /* (1) */
vaadin-text-field::part(input-field) { /* (2) or for all text fields */
width: var(--container-width, 100%);
}
Specify the width in Java:
TextField textField = new TextField("Anzahl aktiver Niederlassungen");
textField.addClassName("custom-width-container"); // add class, only (1)
textField.setWidth("400px"); // maybe not needed
textField.getStyle().set("--container-width", "100px"); // your value