Skip to content

Commit 8d214c4

Browse files
Artur-mshabarov
andauthored
feat: Implement HasStyle in LitTemplate so you can add class names to the root element (#10903)
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 <mikhail@vaadin.com>
1 parent a0a4fa7 commit 8d214c4

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎flow-lit-template/src/main/java/com/vaadin/flow/component/littemplate/LitTemplate.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.vaadin.flow.component.Component;
2121
import com.vaadin.flow.component.HasComponents;
22+
import com.vaadin.flow.component.HasStyle;
2223
import com.vaadin.flow.component.Tag;
2324
import com.vaadin.flow.component.dependency.JsModule;
2425
import com.vaadin.flow.component.littemplate.LitTemplateParser.LitTemplateParserFactory;
@@ -54,7 +55,7 @@
5455
* @author Vaadin Ltd
5556
* @since
5657
*/
57-
public abstract class LitTemplate extends Component {
58+
public abstract class LitTemplate extends Component implements HasStyle {
5859

5960
static {
6061
UsageStatistics.markAsUsed("flow/LitTemplate", null);

‎flow-lit-template/src/test/java/com/vaadin/flow/component/littemplate/LitTemplateTest.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ public ElementWithTextLitTemplate(VaadinService service) {
101101

102102
}
103103

104+
// This is for checking LitTemplate implements HasStyle
105+
@Tag("custom-element-with-class")
106+
private static class ElementWithStyleClass extends LitTemplate {
107+
ElementWithStyleClass() {
108+
// Should be possible to modify the class name
109+
addClassName("custom-element-class-name");
110+
}
111+
}
112+
104113
@Before
105114
public void setUp() {
106115
DeploymentConfiguration configuration = Mockito

0 commit comments

Comments
 (0)