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

Tailwind checkboxes are solid white in dark mode #1199

Closed
bengs opened this issue May 16, 2023 · 13 comments
Closed

Tailwind checkboxes are solid white in dark mode #1199

bengs opened this issue May 16, 2023 · 13 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request Version 2 Version 2 of Package wontfix This will not be worked on

Comments

@bengs
Copy link

bengs commented May 16, 2023

Checkbox classes in the Tailwind views contain both text-indigo-500 and dark:text-white.
This causes checkboxes to display like this when checked in dark mode:
Screenshot 2023-05-16 at 13 41 09.
Solution: remove all dark:text-white classes from checkboxes:
Screenshot 2023-05-16 at 13 42 19.
Also the checkboxes are repeated a little in the code, refactoring them to a blade component might be a good thing to do, so they're utilised similarly to this:

<x-livewire-tables::inputs.checkbox wire:model="selected" wire:loading.attr.delay="disabled" value="{{ $row->{$this->getPrimaryKey()} }}"  />

Then if people want to change look of the checkboxes eg the primary *-indigo-* colour classes they only need to publish & modify classes inside inputs/checkbox.blade.php rather than components inside multiple folders liketable/td, table/th tools etc.

@lrljoe
Copy link
Sponsor Collaborator

lrljoe commented May 16, 2023

Good idea with refactoring into a blade, however bulk actions changes slightly in the next version, as it moves to AlpineJS approach.

I'm currently reviewing more of the blades to get more refactored, and removing some of the existing theme behaviour where the code is repeated, and using conditional classes.

Expect the custom blade for a checkbox to be in the version after this imminent release.

@lrljoe
Copy link
Sponsor Collaborator

lrljoe commented May 16, 2023

I've tested in the current develop stream, and the checkbox works as expected in light/dark modes for Tailwind 2 and 3:

Dark
image

Light
image

I suspect either someone else spotted this and did a PR, or I inadvertently fixed it while migrating the code over to Alpine!

@lrljoe lrljoe added the Awaiting Next Release Currently merged into development awaiting a release to master label May 16, 2023
@lrljoe
Copy link
Sponsor Collaborator

lrljoe commented May 16, 2023

If you can test using the develop branch and let me know if its still an issue or not, then that'd be handy!

@lrljoe lrljoe added the Version 2 Version 2 of Package label May 16, 2023
@bengs
Copy link
Author

bengs commented May 17, 2023

Aha, it's still happening for me on the develop branch but your screenshot was helpful because I'd assumed the checkboxes were supposed to be indigo in both light and dark mode, but in your testing they're white. So the problem is actually with the checked colour classes not working as expected in tailwinds default system dark mode. When I inspect the CSS the dark:bg-gray-900 it is being overriden by the combination of dark:text-white and the following @tailwindcss/forms CSS:

[type="checkbox"]:checked, [type="radio"]:checked {
  border-color: transparent;
  background-color: currentColor;
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

Which picks up on the dark:text-white and also makes the background colour white.
Screenshot of applied CSS:
Screenshot 2023-05-17 at 14 18 45

However if you use darkMode: 'class', in your tailwind config, then it works because this CSS takes precedence:

:is(.dark .dark\:bg-gray-900) {
  --tw-bg-opacity: 1;
  background-color: rgb(17 24 39 / var(--tw-bg-opacity));
}

There is an open tailwind forms issue for it here.
Personally I think the checkboxes work well as indigo in both light and dark modes, but either way if we follow Adam Wathan's suggested fix changing the active checkbox colours to utilise checked:bg-* instead of text-* colours that works. Here's a copy of your bulk-actions.blade.php checkbox classes using checked:bg-indigo-600 and dark:checked-bg-indigo-500 etc instead of text colours and that equalises the behaviour across both dark modes for me:

<input class="rounded border-gray-300 checked:bg-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:checked:bg-indigo-500 dark:checked:focus:bg-indigo-500 dark:checked:hover:bg-indigo-500 dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600" type="checkbox" />

End result in dark system and class mode (I'm focussed on the first checkbox here):
Screenshot 2023-05-17 at 16 46 06
Light:
Screenshot 2023-05-17 at 16 50 33

@bengs
Copy link
Author

bengs commented May 17, 2023

Also nice work with the Alpine checkboxes on the develop branch, they're notably more responsive to toggle.

@lrljoe
Copy link
Sponsor Collaborator

lrljoe commented May 17, 2023

No problem, more to come imminently in AlpineJS migrations as it really smooths the experience.

@lrljoe lrljoe added enhancement New feature or request and removed Awaiting Next Release Currently merged into development awaiting a release to master labels May 18, 2023
@lrljoe
Copy link
Sponsor Collaborator

lrljoe commented May 18, 2023

Tweaked the labels so that I've captured the enhancement request with the blade for checkboxes.

@lrljoe
Copy link
Sponsor Collaborator

lrljoe commented May 21, 2023

Just to update, and be realistic! In terms of refactoring checkboxes into a blade. This is on the roadmap, but not in an immediate release.

It may not even be present until 3.x, as I've recently been reviewing the blades as a whole, and migrating to a smoother experience is such a large piece of work, that it's likely to make it into 3.x instead.

I will however look closely at the form inputs, and see if I can refactor them as an interim measure

@iamgoodbytes
Copy link

Hey friends, bumped into this issue as well and saw that it was logged here. I updated to 2.14 but still have the white on white checkboxes. Is that something that will be released later?

I tried to find it in the CHANGELOG but that mentioned "Bulk Actions (alpine.js)".

Just checking. Thanks to both for picking this up!

@bengs
Copy link
Author

bengs commented May 22, 2023

@iamgoodbytes it might be a while before it's fixed but a quick fix in the meantime is to set dark mode manually by adding darkMode: 'class', to your tailwind.config.js file like this:

module.exports = {
  darkMode: 'class',
  // ...
}

And adding a dark class to your <html> element:

<html lang="en" class="dark">

More info here: https://tailwindcss.com/docs/dark-mode#toggling-dark-mode-manually

@iamgoodbytes
Copy link

Thanks @bengs - that does the trick!

@lrljoe
Copy link
Sponsor Collaborator

lrljoe commented May 24, 2023

I'll make a note to update the docs to reference dark mode, thought it was in there already to be honest.

@lrljoe lrljoe added the documentation Improvements or additions to documentation label May 24, 2023
@stale
Copy link

stale bot commented Jun 24, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jun 24, 2023
@stale stale bot closed this as completed Jul 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request Version 2 Version 2 of Package wontfix This will not be worked on
Projects
Archived in project
Development

No branches or pull requests

3 participants