Skip to content

Add Java API for changing the variant of the theme (light / dark) #15354

@samie

Description

@samie

Describe your motivation

As discussed in vaadin/flow-components#3600 you cannot just set the theme in body element, but it needs to be applied html element instead. This leads to calling JS in instead of using Java API for setting theme.

Logical use case is: "I want to set the theme for my application." Specifically e.g. "I want my application to use dark theme".

Currently this would be:
UI.getCurrent().getPage().executeJs("document.documentElement.setAttribute('theme', '"+Lumo.DARK+"')");

Describe the solution you'd like

Since page-level API is needed a logical API would be:
UI.getPage().getThemeList().set(Lumo.DARK, true);

Describe alternatives you've considered

From application developer point of view UI.getThemeList would make more sense, but since it is likely needing the the Page level API internally, it would be more natural starting point for Java API.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions