Vaadin Grid wrap labels in componentColumns

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Vaadin Grid wrap labels in componentColumns



I'm currently working on a webapp project in Vaadin 10. On the main page there's an overview of your current chats. Each chat is displayed as a bubble looking like:


Vaadin 10




It contains an image and a label.



I placed the bubbles in a Grid to ensure fast loading and flexibility like this:


`Grid<VisualGroup> cloudGrid = new Grid<VisualGroup>();
cloudGrid.setWidth("100%");
cloudGrid.setHeight("100%");
cloudGrid.getElement().getStyle().set("border","white");
cloudGrid.addComponentColumn(VisualGroupComponent::new);
cloudGrid.setItems(groups);`



My problem is that the label does not wrap when I put the components in the grid. If I create the component independently the text wraps correctly like:





But if I use the grid like described above it looks:





Does anyone know how to get text wrapping working in ComponentColumns in vaadin?



EDIT:
I finally got it working, even though it seams like a pretty hacky solution to me. The problem is, that the elements inside the grid layout inherit most of their style values from the grid. And the grid seems to forbid wrapping somewhere. Because the usual html Tags linke word-break: break-word; and
word-wrap: break-word; did not work I found a workaround by resetting the style of the text with all:initial. This completely resets the style and you need to set the important attributes like font-family:var(--lumo-font-family) manually to achieve the same look. But now the wrapping works.


word-break: break-word;


word-wrap: break-word;


all:initial


font-family:var(--lumo-font-family)



If anyone knows the exact attribute I need to overwrite to get just the wrapping working and not delete every thing else that would probaly the best solution. But for now that is a workaround.





Using Label is not adviced to be used with ComponentColumns (more info is found here: github.com/vaadin/flow/issues/4394, and her github.com/vaadin/flow/issues/3532, which warns possible issues regarding accessibility). There is also discussion about re-naming of the component (see: github.com/vaadin/flow/issues/4384)
– Tatu Lund
2 hours ago





@TatuLund Thanks. I did not know that you are not supposed to use Labels in that way. What Component should I correctly use instead for displaying text in a custom component that needs to go into a grid view?
– Voleuro
1 hour ago





One alternative would be to compose them in Div.
– Tatu Lund
24 mins ago





You mean something like Div name = new Div(); name.setText(group.getName());? I've got the same wrapping problem there. When creating the Component directly the text wraps correctly, but it doesn't wrap at all when placed inside a Grid.
– Voleuro
16 mins ago


Div name = new Div(); name.setText(group.getName());









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

C# - How to create a semi transparent or blurred backcolor on windows form

Swipe gestures in WKWebView

How to populate data on nav-tab in partial View in MVC?