Skip to content

feat(checkbox): add checkbox indeterminate prop #1155

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

Closed

Conversation

grasdira
Copy link

@grasdira grasdira commented Nov 28, 2023

Start from the discussion #870

Related to #871

There are no breaking API changes.
Here are my changes:

  1. To ensure that checkboxes with an indeterminate state display the correct style, this commit(65e9f8b) added the following CSS in both .storybook/style.css and docs.css to override the default styles:
[type='checkbox']:indeterminate {
  background-image: url('data:image/svg+xml;base64,PHN2ZyBhcmlhLWhpZGRlbj0ndHJ1ZScgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJyBmaWxsPSdub25lJyB2aWV3Qm94PScwIDAgMTYgMTInPgogIDxwYXRoIHN0cm9rZT0nd2hpdGUnIHN0cm9rZS1saW5lY2FwPSdyb3VuZCcgc3Ryb2tlLXdpZHRoPSczJyBkPSdNMCA2SDE2Jy8+Cjwvc3ZnPg==');
  background-color: currentColor;
}
  1. This commit(f1a8478) added a new example of using the indeterminate state to handle multiple checkboxes in a group or tree structure.

Copy link

vercel bot commented Nov 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 4, 2024 1:23pm

Copy link

codecov bot commented Nov 28, 2023

Codecov Report

Attention: Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.

Project coverage is 97.29%. Comparing base (7461173) to head (1586050).
Report is 275 commits behind head on main.

Files with missing lines Patch % Lines
src/components/Checkbox/Checkbox.tsx 73.91% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1155      +/-   ##
==========================================
- Coverage   99.54%   97.29%   -2.26%     
==========================================
  Files         163      216      +53     
  Lines        6621     9244    +2623     
  Branches      401      541     +140     
==========================================
+ Hits         6591     8994    +2403     
- Misses         30      250     +220     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tulup-conner tulup-conner force-pushed the feat/checkbox-indeterminate-prop branch from f1a8478 to 22e6f68 Compare November 30, 2023 01:02
@tulup-conner
Copy link
Collaborator

Hey thanks for the contribution! I don't have the time to look at this right now but forgive me for jumping in and rebasing, we're trying to figure out what's wrong with codecov. Thank you for your patience! @grasdira

const theme = mergeDeep(getTheme().checkbox, customTheme);

const inputRef = useRef<HTMLInputElement | null>(null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't this be done using custom data attribute prop (eg: data-...) instead of injecting it through ref and checking the data attribute with tailwind directly in this file? 🤔

Copy link
Author

@grasdira grasdira Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @SutuSebastian . I have provided my responses in this comment. Please review them at your earliest convenience.

@Stupidism
Copy link

Anyone still working on this?

@SutuSebastian
Copy link
Collaborator

Anyone still working on this?

Doesn't seem like it 🤔

@grasdira
Copy link
Author

I'm really sorry for not keeping up with this PR 😔
Since not quite familiar with this project, I need more help to discuss how to solve this problem.

@grasdira
Copy link
Author

Hi!
After rethinking the code, I have made some adjustments to provide developers with more flexibility when using the component:

  1. I am continuing to use useRef to directly set the indeterminate property on the DOM element. This enables the use of the pseudo-class modifiers indeterminate: in TailwindCSS for CSS customization. (@SutuSebastian sorry for taking so long to reply, this point is why I don't think data-... is a better way on this feature. )
  2. I have removed the modifications I previously made in two .css files, realizing that this approach was limiting the developers’ ability to change the icon or other styles for the indeterminate state. (90ec304)
  3. In tailwind.config.ts, I have extended indeterminate backgroundImage(a4af18f) and set the CSS for the indeterminate checkbox with indeterminate: modifier in Checkbox.tsx(a1bfc21).

What are your opinions on these changes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforcing the users to apply the same config into their tailwind config is not the way to go, the only thing they'd have to configure is primary and secondary colors override, if needed.

On top of that, needing a custom tailwind config just for a simple component state, is a bit over-engineered. We need to find a simple solution here, that does not spill out more than the components context/folder.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I certainly understand we should not ask user to update their Tailwind config. But I do noticed that the indeterminate state's style definition isn't covered by default in Flowbite.

Is it a better way to integrate indeterminate state's styles directly into Flowbite's default stylesheet, so that all users have access without extra configuration?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U mean to include the indeterminate into flowbite/plugin?

I'd rather have it at the component level, its just a matter of a dash icon and an extra prop.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also see in the core library plugin, we already have it: https://github.com/themesberg/flowbite/blob/main/plugin.js#L350

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware that the indeterminate state's style had already been defined in the plugin. Thank you for pointing me to it.
I'll update and resubmit shortly.

Copy link
Author

@grasdira grasdira Mar 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SutuSebastian Hey, am I allowed to update flowbite to the latest version.
I just found out the indeterminate state icon changed in a recent commit , and it's causing the icon keep showing the check icon before. 😲

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, go ahead

grasdira added 7 commits March 3, 2024 20:20
…f checkbox :indeterminate

Override the original style of [type='checkbox']:indeterminate.

themesberg#871
…r indeterminate checkbox

Add an example of using the indeterminate state to handle multiple checkboxes in a group of tree
structure.

themesberg#871
Added extended theme 'colors.current' and 'backgroundImage.indeterminate' to set default styles for
indeterminate checkbox

themesberg#871
…yles

remove [type='checkbox']:indeterminate styles to make development more flexibility

themesberg#871
…the indeterminate state

'indeterminate:bg-indeterminate' uses the extended backgroundImage in `tailwind.config.ts`;
'dark:indeterminate:bg-current dark:indeterminate:border-gray-600' fixes checkbox's bg-color and
border under dark mode

themesberg#871
@grasdira grasdira force-pushed the feat/checkbox-indeterminate-prop branch from a1bfc21 to 1943cc3 Compare March 3, 2024 12:30
@grasdira grasdira marked this pull request as draft March 3, 2024 12:32
@grasdira grasdira marked this pull request as ready for review March 4, 2024 13:17
@grasdira grasdira requested a review from SutuSebastian March 4, 2024 13:18
@grasdira grasdira closed this Mar 17, 2025
@SutuSebastian SutuSebastian mentioned this pull request Mar 17, 2025
24 tasks
@github-actions github-actions bot mentioned this pull request Mar 24, 2025
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.

4 participants