Skip to content

Commit

Permalink
feat: add support for applying theme in iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-godoy authored and paodb committed Jan 9, 2025
1 parent 941a025 commit e36441d
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,14 @@ public static void applyTheme(Element element, boolean useDarkTheme) {
public static void applyTheme(Element element, String theme) {
VaadinSession.getCurrent().setAttribute(THEME_NAME, theme);

element.executeJs("document.body.setAttribute('theme', $0);", theme);
String script;
if (element.getTag().equalsIgnoreCase("iframe")) {
script = "this.contentWindow.document.body.setAttribute('theme', $0)";
} else {
script = "document.body.setAttribute('theme', $0);";
}

element.executeJs(script, theme);

Component c = element.getComponent().get();
collectThemeChangeObservers(c).forEach(observer -> observer.onThemeChange(theme));
Expand Down

0 comments on commit e36441d

Please sign in to comment.