|
39 | 39 | import com.vaadin.flow.router.PageTitle; |
40 | 40 | import com.vaadin.flow.router.Route; |
41 | 41 | import com.vaadin.flow.router.RouterLayout; |
| 42 | +import com.vaadin.flow.server.VaadinSession; |
42 | 43 | import java.util.ArrayList; |
43 | 44 | import java.util.List; |
44 | 45 | import java.util.Objects; |
@@ -227,6 +228,8 @@ public void showRouterLayoutContent(HasElement content) { |
227 | 228 |
|
228 | 229 | updateFooterButtonsVisibility(); |
229 | 230 | getElement().insertChild(1, content.getElement()); |
| 231 | + |
| 232 | + applyTheme(getElement(), getThemeName()); |
230 | 233 | } |
231 | 234 |
|
232 | 235 | private Optional<SourceCodeTab> createSourceCodeTab(Class<?> annotatedClass, DemoSource annotation) { |
@@ -338,8 +341,22 @@ public void setOrientation(Orientation orientation) { |
338 | 341 | orientationCB.setValue(Orientation.HORIZONTAL.equals(orientation)); |
339 | 342 | } |
340 | 343 |
|
| 344 | + private static final String THEME_NAME = TabbedDemo.class.getName() + "#THEME_NAME"; |
| 345 | + |
| 346 | + public static String getThemeName() { |
| 347 | + return (String) Optional.ofNullable(VaadinSession.getCurrent().getAttribute(THEME_NAME)) |
| 348 | + .orElse(""); |
| 349 | + } |
| 350 | + |
| 351 | + @Deprecated |
341 | 352 | public static void applyTheme(Element element, boolean useDarkTheme) { |
342 | 353 | String theme = useDarkTheme ? "dark" : ""; |
| 354 | + applyTheme(element, theme); |
| 355 | + } |
| 356 | + |
| 357 | + public static void applyTheme(Element element, String theme) { |
| 358 | + VaadinSession.getCurrent().setAttribute(THEME_NAME, theme); |
| 359 | + |
343 | 360 | element.executeJs("document.documentElement.setAttribute('theme', $0);", theme); |
344 | 361 |
|
345 | 362 | Component c = element.getComponent().get(); |
|
0 commit comments