-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add icon to field title #6756
Comments
Related to vaadin/web-components#5786 As a workaround, a custom label element can be slotted into the component: var labelIcon = VaadinIcon.ALARM.create();
labelIcon.setSize("1em");
var labelText = new Span("Label");
var label = new NativeLabel();
label.add(labelIcon, labelText);
label.addClassNames(LumoUtility.Display.FLEX, LumoUtility.AlignItems.CENTER, LumoUtility.Gap.XSMALL);
label.getElement().setAttribute("slot", "label");
var textField = new TextField();
textField.getElement().appendChild(label.getElement()); |
Thanks, Sascha, this looks promising, I will try that. |
I made this utility method, but not sure about unsetting the icon. Is there a more elegant way?
|
I think the logic doesn't quite add up. You remove the icon component from a potentially existing label component, but when you actually want to set an icon then you create a new label component anyway. So if you call this method multiple times you'll end up with multiple label components. The easiest would be to just remove the existing label, if it exists, and then create a new one. If you want to optimize then you'd have to get the existing label or create a new one if it doesn't exist. Then update the icon and label text on it. If you want to avoid iterating through children, then you could create a |
Thanks for pointing this out. So the workaround works well, now waiting for an "official" solution. :) |
Describe your motivation
In Vaadin 8 each input field had the option to specify an icon with setIcon() which would be rendered before the field's label. In Flow this does not exist anymore. Some, but not all components have prefix/suffic icons which are rendered inside the field. There are helper components which are either rendered above or below input field, but when used at runtime (e. g. for marking a changed field) it makes the layout very bumpy.
Describe the solution you'd like
Please add setIcon() to input fields and render that icon before the label just as in Vaadin 8
OR
make the caption/title a component so one can set e. g. a HorizontalLayout, similar to DialogHeader.
Describe alternatives you've considered
I tried tweaking CSS so that the helper component would be rendered before the label. I also tried the NativeLabel component. Appropriate styling seems cumbersome in both cases.
The text was updated successfully, but these errors were encountered: