[Checkbox] Allow Checkbox BubbleInput to pass validation state when used within Form primitive #3221
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The changes in this PR enable the use of
Checkbox
within theForm
primitive, and have validation hooked up forvalueMissing
when checkbox is not ticked. To achieve this, we trigger a change event on the underlyingBubbleInput
component when the checked state is changed for theCheckbox
. TheonInvalid
callback is passed intoBubbleInput
instead of the button element to ensure validation is properly handled when used within theForm
primitive. In this open issue #2659 someone mentioned the issue with focusing on aria-hidden elements, and I've added a span around the input to get around the error.I found this comment on the Radix website, but I've not found an associated PR. If someone is already working on this, appreciate a link to the branch to compare and/or merge changes.
Additional unit tests have been added to
Checkbox
to test the input change event is fired. I've also added an additionalCheckbox
story to show it working with theForm
primitive.Partially fixes #2659 . Appreciate this PR doesn't solve not being able to use
Select
inForm
properly. I wanted to make sure the solution is acceptable forCheckbox
before having a crack atSelect
next.