-
Notifications
You must be signed in to change notification settings - Fork 190
feat: add ColorScheme API for light/dark theme support #22718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Rather than making it work differently with Lumo and Aura, we should align the themes to work the same way. Either both offer a |
|
Please do |
fa58500 to
4b6d9a3
Compare
d97b63b to
ec54cee
Compare
Adds Page.setThemeVariant() and Page.getThemeVariant() methods to enable runtime switching between theme variants without requiring manual JavaScript execution. The theme variant is automatically synced from the browser on page load if set in index.html. The implementation supports both Lumo and Aura themes: - Lumo: Sets/removes the 'theme' attribute on the HTML element - Aura: Sets/removes the '--aura-color-scheme' CSS custom property Key changes: - Page API: setThemeVariant() and getThemeVariant() methods - UIInternals: cache theme variant for quick access (returns "" not null) - ExtendedClientDetails: include theme variant from browser - FlowBootstrap.js: sync theme attribute and Aura color scheme on page load - Comprehensive unit and integration tests Fixes #15354
ec54cee to
a228ebb
Compare
...sts/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/ExtendedClientDetailsView.java
Outdated
Show resolved
Hide resolved
flow-server/src/test/java/com/vaadin/flow/component/page/PageTest.java
Outdated
Show resolved
Hide resolved
flow-server/src/test/java/com/vaadin/flow/component/page/PageTest.java
Outdated
Show resolved
Hide resolved
jouni
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change request concerning the use of --aura-color-scheme which no longer exists.
Why do we need the theme name? It’ll be an empty string for any custom theme not built on top of Lumo or Aura. I feel this feature should be a simple theme-agnostic way of setting attribute values on the <html> document element.
Given the discussion about possibly moving away from the theme attribute in future major versions (correct me if I remember wrong, @rolfsmeds and @web-padawan), I’m unsure if we should build more API explicitly for that.
The themeVariant field in ExtendedClientDetails is null until first initialized, consistent with other fields like windowName. Added null check in Page.getThemeVariant() to ensure it always returns an empty string instead of null when the theme variant hasn't been set yet.
What does this refer to? The API added is for getting the variant: dark or light. It can be set using an attribute or using magic fairy dust and this API stays the same |
Depends on who "we" are. Some add-on authors will presumably use it to customize some behavior to better match Aura or Lumo defaults, and use either one as the fallback if you have a completely custom theme. |
The --aura-color-scheme CSS custom property has been replaced with the native color-scheme property in Aura theme. Updated the fallback logic to check for the standard color-scheme property when the theme attribute is not present.
|
Changed the whole API to be based on |
|
Component level API in #22799 |
- IndexHtmlRequestHandler now sets theme attribute instead of inline style - Updated PageTest to check for theme attribute and style clearing - Both @colorscheme and @theme(variant) now set theme attribute consistently - All tests pass
flow-server/src/main/java/com/vaadin/flow/component/page/Page.java
Outdated
Show resolved
Hide resolved
"System" is sometimes/often used to indicate The |
flow-server/src/main/java/com/vaadin/flow/component/page/ColorScheme.java
Outdated
Show resolved
Hide resolved
flow-server/src/main/java/com/vaadin/flow/component/page/Page.java
Outdated
Show resolved
Hide resolved
NORMAL doesn't force browser default behavior - it just means no color scheme is set via this API. The actual behavior depends on other factors like browser defaults, system preferences, or meta tags.
Addresses review feedback - sets both theme attribute and color-scheme property to support custom themes that don't define their own CSS rules. The theme attribute enables CSS targeting (html[theme~='dark']), while the inline color-scheme property ensures browser UI adaptation works universally, even for custom themes. - Updated Page.java to set property instead of clearing it - Updated documentation to explain dual-setting approach - Updated all tests to verify both attribute and property - All integration tests passing (6/6)
For multi-value color schemes like LIGHT_DARK, the theme attribute now uses hyphens (e.g., "light-dark") while the CSS color-scheme property uses spaces (e.g., "light dark"). - Added getThemeValue() method to ColorScheme.Value enum - Updated Page.setColorScheme() to pass separate values for theme attribute and CSS property - Updated IndexHtmlRequestHandler to use getThemeValue() - Added ColorSchemeTest to verify enum behavior - Updated PageTest with test for LIGHT_DARK handling - All unit and integration tests passing
|
Let's wait for @jouni then |
|
|
This ticket/PR has been released with Vaadin 25.0.0-beta8. |



Adds a ColorScheme API for controlling light and dark theme variants in Vaadin applications. Includes an @colorscheme annotation for initial configuration and Page.setColorScheme() for runtime switching. Uses the HTML theme attribute approach for CSS compatibility.
Initial Configuration
Runtime Control
Implementation Details
Backward Compatibility
Fixes #15354