Open norman-ags opened 10 months ago
I completely agree on this and for the record the issue is not limited to RHF.
@tanstack/table
is also impacted via RowSelection api where it expects something like
onChange={table.getToggleAllRowsSelectedHandler()}
With Radix, you cannot use this method because onChange
is never triggered.
You also cannot use onCheckedChange={table.getToggleAllRowsSelectedHandler()}
because getToggleAllRowsSelectedHandler
expect an event.
The workaround is to use something like
onCheckedChange={(checked) => {
if (checked === 'indeterminate') {
return
}
table.toggleAllRowsSelected(checked)
}}
This is very complicated / weird for something like a checkbox, where you expect to behave like native HTML
Bumping this as it's a big pain point for me as well. Also willing to contribute if there's an interest from the maintainers.
Overview
I noticed radix-checkbox component doesn't work with RHF register. It doesn't work because it's expecting ref.current.checked (just like a native HTML input)
Saw this issue in github: https://github.com/radix-ui/primitives/issues/734
I think using
onCheckedChange={field.onChange}
should be a secondary option. IMO, a "CustomCheckbox" should be close to native HTML as possible. With that said I think the ref should havechecked
property.This is just my opinion and if radix team think this is also correct, I'm happy to help/do a PR for this.