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

Restore old behavior for class dark mode, add new selector and variant options for dark mode #12717

Merged
merged 24 commits into from
Jan 5, 2024

Conversation

thecrypticace
Copy link
Contributor

When we release v3.4 we changed darkMode: "class" to use :where and changed the sort order so it does not have a higher specificity. This also makes it act the same as darkMode: "media".

Some projects depended heavily on the higher selector specificity rather than using variants to explicitly handle light vs dark mode, dark mode vs hover styles, etc… This made this a pretty large breaking change.

This PR does two things:

  1. It reverts the change such that darkMode: "class" works the way it did in v3.3. This includes the difference in sorting.
  2. A new strategy has been added darkMode: "selector" which uses the new :where() behavior and sort order and as such makes this change opt-in.

Fixes #12633

@thecrypticace thecrypticace changed the title Restore old behavior for darkMode: "class" and add new darkMode: "selector" option Restore old behavior for class dark mode, add new selector and variant options for dark mode Jan 5, 2024
@thecrypticace thecrypticace merged commit fb1743b into master Jan 5, 2024
10 checks passed
@thecrypticace thecrypticace deleted the feat/dark-mode-variant branch January 5, 2024 19:39
thecrypticace added a commit that referenced this pull request Jan 5, 2024
…ariant` options for dark mode (#12717)

* Add dark mode variant option

* Tweak warning messages

* Add legacy dark mode option

* wip

* Use `class` for legacy behavior, `selector` for new behavior

* Add simplified failing apply/where test case

* Switch to `where` list, apply changes to `dir` variants

* Don’t let `:where`, `:is:`, or `:has` be attached to pseudo elements

* Updating tests...

* Finish updating tests

* Remove `variant` dark mode strategy

* Update types

* Update comments

* Update changelog

* Revert "Remove `variant` dark mode strategy"

This reverts commit 1852504.

* Add variant back to types

* wip

* Update comments

* Update tests

* Rename variable

* Update changelog

* Update changelog

* Update changelog

* Fix CS

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
@ovoander
Copy link

ovoander commented Jan 6, 2024

Nice

@ngbrown
Copy link

ngbrown commented Jan 8, 2024

The documentation (https://tailwindcss.com/docs/dark-mode) needs updated to include the darkMode: "selector" option.

Also, it's not clear from the linked issues what scenarios do and don't work with each of the two options.

Update - this is my summary on the issue:

The new darkMode: "selector" option lowers the specificity of the dark: modifier when using a dark class to make it the same as when using the darkMode: "media" option (see #12584). A side effect is that class based dark: is now less specific than pseudo-classes like hover:. To correctly style elements, a combined dark:hover: should to be applied to elements instead of expecting the hover: to be overridden.

From the examples linked in the issue #12633, it appears that the skeleton library pre-built CSS content for .dark .card {} and the new lowered specifier of the :where(.dark) in :is(:where(.dark) .dark\:bg-*) didn't override it in 3.4.0 like it did before (now reverted in 3.4.1, and the reason for this new dark mode option).

For the button example, without a dark:hover:bg-* class specified, when hovering the background falls back to hover:bg-* because it has a higher specificity. This is the same behavior as when using the darkMode: "media" option. The solution is to have a hover for dark mode too.

javierjulio added a commit to activeadmin/activeadmin that referenced this pull request Feb 26, 2024
javierjulio added a commit to activeadmin/activeadmin that referenced this pull request Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dark mode broken in 3.4.0, last working 3.3.7
4 participants