Please add API on server-side Button to add/remove themes
mvysny opened this issue · 8 comments
According to https://vaadin.com/elements/vaadin-button/html-examples/button-lumo-theme-demos the button can have themes. For example, to create a borderless icon button I would like to have the theme of "icon tertiary small". However I am not able to do that from server-side: the Button java class does not have any support for setting theme.
Thanks for the suggestion. The proper repo would be https://github.com/vaadin/vaadin-button-flow, though.
AFAIK there should be a component.getThemeList().add(String)
available in Flow.
Thanks jouni. Should I create a bug report in vaadin-button-flow, or in the flow itself?
Dunno. But you already have getThemeList()
, so you can at least use plain Strings with that: https://github.com/vaadin/flow/blob/443c0ba2c5254f77e0ad4516d61707469d8af761/flow-server/src/main/java/com/vaadin/flow/dom/Element.java#L1065-L1079
If you want Enums for the available theme variants, those don’t exist yet AFAIK. If you want those, I think you can open a new issue for vaadin-button-flow, although the same applies to all components, really. So maybe in the Flow repo then?
Just to add, the method is in the Element
class, you you need to do
button.getElement().getThemeList().add("icon");
button.getElement().getThemeList().add("tertiary");
button.getElement().getThemeList().add("small");
Thanks for the help!
I perceive this as bit confusing: why does not the Component implement the HasStyles directly? Why HasStyles
is only implemented by particular subclasses of the Component, even though the Component directly implements HasElement? Shouldn't HasStyle has support for themes?
I don’t know the answer to that, sorry.
Guillermo also pointed out this piece of code, that probably prevents you from using any other theme variants together with icon-only buttons: https://github.com/vaadin/vaadin-button-flow/blob/master/src/main/java/com/vaadin/flow/component/button/Button.java#L395-L407
I’ll move this issue to the Flow button repo.
This issue was moved to vaadin/vaadin-button-flow#45
With Kotlin the workaround is easy: val HasElement.themes: ThemeList get() = element.themeList