-
Notifications
You must be signed in to change notification settings - Fork 296
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
feat: add checkbox indeterminate #1154
feat: add checkbox indeterminate #1154
Conversation
🦋 Changeset detectedLatest commit: 8d2b251 The changes in this PR will be included in the next version bump. This PR includes changesets to release 21 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Hey, I think the behaviour looks good and I like the API way better than my POC, good idea to add a small hook afterTemplate and use it in CheckboxIndeterminate with Indeed what @gerjanvangeest said about sibling indeterminate checkboxes is true, we need to ensure that we only check subcheckboxes that are children of the indeterminate one. So to continue on this PR:
Later, in a separate PR:
One last thing, do we want to support: <lion-checkbox-group name="scientists[]" label="Favorite scientists">
<lion-checkbox-indeterminate label="Scientists">
<lion-checkbox label="Isaac Newton" .choiceValue=${'Isaac Newton'}></lion-checkbox>
<lion-checkbox label="Galileo Galilei" .choiceValue=${'Galileo Galilei'}></lion-checkbox>
<lion-checkbox-indeterminate label="Old Greek scientists">
<lion-checkbox label="Archimedes" .choiceValue=${'Archimedes'}></lion-checkbox>
<lion-checkbox label="Plato" .choiceValue=${'Plato'}></lion-checkbox>
<lion-checkbox label="Pythagoras" .choiceValue=${'Pythagoras'}></lion-checkbox>
</lion-checkbox-indeterminate>
</lion-checkbox-indeterminate>
</lion-checkbox-group> That would mean that selecting the very last checkbox ( With my suggestion in the comment earlier to do So if we support that use case, we also will need some tests for that of course :) |
I couldn't help myself, made some improvements MatthieuLebigre#1 feel free to check them out before merging to this. I just really wanted to see if the nested indeterminates would work and they do 🎉 😱 |
Hello all !! Thanks all for the comments and suggestions ? I'll fix everything when I'll come back from vacation (beginning of January) :) |
Huh thanks to Thijs' comment I noticed we dont have to listen to input /**
* @override ChoiceInputMixin
* first set subCheckboxes if event came from itself
* then set own checked + indeterminate state
* @param {Event} ev
*/
__toggleChecked(ev) {
if (this.disabled) {
return;
}
if (ev.target === this) {
this._subCheckboxes.forEach(checkbox => {
// eslint-disable-next-line no-param-reassign
checkbox.checked = this._inputNode.checked;
});
}
this._setOwnCheckedState();
} I guess __parentFormGroup and __toggleChecked should be made protected with a single underscore 🙈 can fix that too while we're at it I updated my PR to your fork @MatthieuLebigre as well as the checklist I wrote above 👍 have a nice holiday and see you in 2021! |
Think I created something similar yesterday: https://github.com/ing-bank/lion/blob/feat/checkbox-indeterminate-enhancements/packages/checkbox-group/src/LionCheckboxIndeterminate.js#L85 This handles readonly and tristate (it captures indeterminate states, also taking into account users 'meddling' with the captured state by (un)selecting all). Maybe will have a deeper look on Monday. If you can't wait on that, that's fine with me :) we can also add those details later |
@jorenbroekema I merged your PR, it should be easier to track all changes in this one. |
I did a few changes/fix based on the feedback. I also started to add unit tests. I'll continue on that topic, but I believe for the code itself it should be fine now |
Tests are looking good @MatthieuLebigre ! Just a few left, I updated the checklist. After those last tests are in, I'll do a full review and finish things up and release 👍 |
037df1c
to
d02eb12
Compare
Done @jorenbroekema |
d02eb12
to
4b3f47e
Compare
4b3f47e
to
8d2b251
Compare
Yay, thanks @MatthieuLebigre for contributing and for collaborating on this with us 🤗 |
What I did
Based on #1128, and inspired by #1134, I open this PR to add the checkbox with indeterminate state.
What is different from #1134 is mostly that I added the nested checkbox in the slot of the
lion-checkbox-indeterminate
instead of being siblings.This my first PR in lion, so any feedback will be appreciated, I will update the PR based on your comments.