Hi. Styling the components in shadow DOM is only possible using CSS custom properties (this is how browsers work). So the working code for your case looks like this:
This will not work (using CSS) as the variable is targetting all text-fields input-field parts, as it is used in the “themeFor” text-fields. However, it is null for all others than the combo-box in which “themeFor”, it specifically is declared and thus known to. In the example below, making the text-fields background unknown.
… or do I miss something?
Main class:
@Theme(value = Lumo.class)
@CssImport(value="./styles/my-textfieldstyles.css", themeFor="vaadin-text-field")
@CssImport(value="./styles/my-comboboxstyles.css", themeFor="vaadin-combo-box")
public class MainView extends VerticalLayout {
TextField tf1 = new TextField("Textfield 1");
ComboBox<String> cb1 = new ComboBox<String>("Combo1");
public MainView() {
tf1.setClassName("my-textfield");
cb1.setClassName("my-combobox");
add(tf1,cb1);
}
}
my-comboboxstyles.css
:host(.my-combobox) [part="text-field"]
{
--my-cb-background: blue
}