Is there a way to apply a variant (say the small variant) to all the components in a view?

The LUMO_SMALL variant seems to always be just “small” but I can’t seem to find a way to do something like:

components.forEach(component → ((ThemeVariant)component).addThemeVariant(“small”));

Or something along those lines. Instead I’m essentially having to do:

if(component instanceof TextField textField)
textField.addThemeVariant(TextFieldVariant.LUMO_SMALL);

and so on for each component type.

The reason for this is I have a grid that I’d like to offer in both compact mode where I’d also like to have all the components compact. And rather than doing this over multiple grids it would be nice to do in one spot but I can’t see to figure out a way to do it…

Take a look what addThemeVariant does and it gets pretty simple

The main issue is that it requires a TVariantEnum

Oh you mean the actual source. I get what you’re saying. Thank you.

In the end ist’s just getElement().setAttribute(“theme”, str);

I can’t believe I missed that. Good call. Thank you.