-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: checkbox validation reset not working #7268
base: main
Are you sure you want to change the base?
Conversation
@LFDanLu Pipeline seems to be stuck, can someone restart? Otherwise i think this is good to go. |
@LFDanLu I think what @devongovett was referencing here was using Is there a specific reason for |
@nwidynski I don't quite remember if there was a specific reason for not accepting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, verified the proper behavior on both the RAC/RSP docs and in our storybook examples. Thank you so much for coming back and picking this one back up!
// Reset validation state on label click for checkbox with a hidden input. | ||
state.toggle = chain(state.toggle, () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A coworker pointed out that this is mutating the state object and thus if the child that called useCheckbox
is rerendering more than the state is being recreated then multiple state.toggles
could be chained here. What do you think about just calling usePress
in here and duplicating what useToggle
does for labelProps? A bit gross that we'd be duplicating the code but maybe good enough for now until we decide whether or not useToggle should accept press handlers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 👍
I don't think it matters as useToggleState
isn't memoized anyways, but we can usePress
here if you want to make sure. Alternatively, if you don't like a duplicated usePress
, we could memoize instead.
state.toggle = chain(useCallback(state.toggle, [isSelected]), () => {
...
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't like mutating the state object, it breaks some assumptions and makes it harder to debug.
I'd prefer to just duplicate the code.
Co-authored-by: Daniel Lu <danilu@adobe.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
Replaces #6079
Closes #5693
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: