vaadin / vaadin-button-flow

Vaadin Flow Java API for vaadin/vaadin-button Web Component
https://vaadin.com/components/vaadin-button
Other
0 stars 8 forks source link

Changing the icon removes icon theme #93

Closed mas4ivv closed 5 years ago

mas4ivv commented 5 years ago

For a button with an icon only, updateThemeAttribute sets the theme to 'icon'. When I change the icon, the theme is removed. This is quite obvious when looking at the code:

    if (theme == null && getElement().getChildCount() == 1 && iconComponent != null) {
        getElement().setAttribute(THEME_ATTRIBUTE, "icon");
    } else if ("icon".equals(theme)) {
        getElement().removeAttribute(THEME_ATTRIBUTE);
    }

Currently I'm subclassing Button and use this code instead:

    if (theme == null && getElement().getChildCount() == 1 && iconComponent != null) {
        getElement().setAttribute(THEME_ATTRIBUTE, "icon");
    } else if ("icon".equals(theme) && (iconComponent == null || getElement().getChildCount() != 1)) {
        getElement().removeAttribute(THEME_ATTRIBUTE);
    }
mehdi-vaadin commented 5 years ago

The result of the followings isn't the same.

button.addThemeVariants(ButtonVariant.LUMO_SUCCESS);
button.setIcon(new Icon(VaadinIcon.ARROW_RIGHT));
button.setIcon(new Icon(VaadinIcon.ARROW_RIGHT));
button.addThemeVariants(ButtonVariant.LUMO_SUCCESS);