Skip to content
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

Dark mode broken with shadow DOM - :root specifier is missing in dark.css #1842

Closed
iva2k opened this issue Jan 30, 2024 · 3 comments
Closed
Labels
bug Things that aren't working right in the library.

Comments

@iva2k
Copy link

iva2k commented Jan 30, 2024

Describe the bug

Dark mode is broken (e.g. when used in a shadow DOM framework, such as SvelteKit).

Inspecting the sources, light.css has :root specifier on 1st line, but dark.css does not have it.

To Reproduce

diff dist/themes/light.css dist/themes/dark.css | head -n 5

Demo

n/a

Screenshots

n/a

Browser / OS

n/a

Additional information

Inserting :root, as 1st line into dark.css fixes the problem.

@iva2k iva2k added the bug Things that aren't working right in the library. label Jan 30, 2024
@CetinSert
Copy link

For reference, links to the themes at the time of this issue:

@claviska
Copy link
Member

This is how themes are designed to work, not a bug. See this section of the docs:

Root-scoped styles

We default to the light theme as a convention in the light/dark themes we provide using :root. This makes it easier for users to get started, as they can include both the light and dark stylesheets and toggle dark mode using the sl-theme-dark class.

If we scoped tokens to :root in both stylesheets, you couldn't simply toggle a class. This is because the tokens would be competing for the :root scope so the last one included would always win. Instead, you'd have to remove the current stylesheet and add the new one.

Note that this convention isn't a requirement if you're building your own themes. You can scope custom light/dark themes to :root or even just to classes of your choice.

Host-scoped styles

For custom element authors, we do provide :host-scoped styles in both themes. If you include our theme styles inside your custom element's shadow root, you should see the appropriate tokens and styles.

If that's not what you're seeing, feel free to open a new issue with a repro so we can take a look.

@iva2k
Copy link
Author

iva2k commented Feb 1, 2024

@claviska - thanks for the pointers. The code indeed was toggling light and dark theme stylesheets. After changing it to include both stylesheets as suggested, and toggling the class, dark theme works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things that aren't working right in the library.
Projects
None yet
Development

No branches or pull requests

3 participants