Skip to content
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

defaultChecked property does not work when used in radio children components #168

Open
diogob opened this issue Mar 14, 2023 · 2 comments
Open
Assignees
Labels

Comments

@diogob
Copy link
Contributor

diogob commented Mar 14, 2023

Steps to reproduce:

  1. Use the example: test-examples/field-with-radio-children.
  2. Tweak the radio group to introduce a defaultChecked property.
                  <RadioGroup>
                    <RadioWrapper>
                      <Radio value="google" defaultChecked={true} />
                      <Label>Google</Label>
                    </RadioWrapper>
                    <RadioWrapper>
                      <Radio value="fromAFriend" />
                      <Label>From a friend</Label>
                    </RadioWrapper>
                  </RadioGroup>
  1. When the example is updated in the browser there are no checked radios

Expected result

The radio marked with defaultChecked should be selected.

Technical details

It seems that we are properly setting the defaultChecked and then resetting in the useEffect hook used to apply defaults.

@diogob diogob self-assigned this Mar 14, 2023
@diogob diogob added the bug Something isn't working label Mar 14, 2023
@danielweinmann
Copy link
Contributor

This is tricky. I don't think we're supposed to pass defaultChecked or defaultValues to fields directly when using React Hook Form. As far as I can tell, we should register the same field for all radio buttons instead (which Remix Forms does automatically).

@danielweinmann danielweinmann added breaking and removed bug Something isn't working labels Mar 15, 2023
@danielweinmann
Copy link
Contributor

@diogob and I discussed it, and we won't try to fix this now because this is not a bug: it's just how RHF works.

However, we'll leave the issue open because we might want to remove the prop from the components in v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants