Skip to content

Commit

Permalink
feat: Implement HasStyle in LitTemplate so you can add class names to…
Browse files Browse the repository at this point in the history
… the root element (#10903) (#11017)

Makes it possible to use addClassName("hello") in the constructor. Class for the custom element cannot be added in the template.

Co-authored-by: Mikhail Shabarov <[email protected]>
  • Loading branch information
vaadin-bot and mshabarov authored May 18, 2021
1 parent ed88c32 commit a83bb49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasComponents;
import com.vaadin.flow.component.HasStyle;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.littemplate.LitTemplateParser.LitTemplateParserFactory;
Expand Down Expand Up @@ -55,7 +56,7 @@
* @author Vaadin Ltd
* @since
*/
public abstract class LitTemplate extends Component {
public abstract class LitTemplate extends Component implements HasStyle {

static {
UsageStatistics.markAsUsed("flow/LitTemplate", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ public ElementWithTextLitTemplate(VaadinService service) {

}

// This is for checking LitTemplate implements HasStyle
@Tag("custom-element-with-class")
private static class ElementWithStyleClass extends LitTemplate {
ElementWithStyleClass() {
// Should be possible to modify the class name
addClassName("custom-element-class-name");
}
}

@Before
public void setUp() {
DeploymentConfiguration configuration = Mockito
Expand Down

0 comments on commit a83bb49

Please sign in to comment.