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

[BUG] - RadioGroup doesn't work with RHF #4918

Open
UltraWelfare opened this issue Feb 24, 2025 · 4 comments
Open

[BUG] - RadioGroup doesn't work with RHF #4918

UltraWelfare opened this issue Feb 24, 2025 · 4 comments
Labels
📦 Scope : Components Related to the components 🐛 Type: Bug Something isn't working

Comments

@UltraWelfare
Copy link

UltraWelfare commented Feb 24, 2025

HeroUI Version

2.7.2

Describe the bug

When using a RadioGroup with Radio components, toggling to other radio options sets the value on the RHF form to null

Your Example Website or App

Code Sandbox

Steps to Reproduce the Bug or Issue

type Input = {
  type: string,
};

export default function IndexPage() {
  const { register, watch } = useForm<Input>();

  const values = watch();

  console.log(values);

  return (
    <DefaultLayout>
      <Form>
        <RadioGroup label="Type" {...register("type")}>
          <Radio value="customer">Customer</Radio>
          <Radio value="employee">Employee</Radio>
        </RadioGroup>
      </Form>
    </DefaultLayout>
  );
}

Toggling to customer, will console.log { type: "customer" } but toggling to employee will console.log { type: null }

Image

Expected behavior

The value should be set instead of null

Screenshots or Videos

No response

Operating System Version

Windows

Browser

Chrome

Copy link

linear bot commented Feb 24, 2025

@UltraWelfare
Copy link
Author

UltraWelfare commented Feb 24, 2025

Wrapping it in a Controller fixes it as a workaround

<Controller
  control={control}
  name={"type"}
  render={({ field: { onChange, onBlur, value } }) => (
    <RadioGroup
      label="Type"
      value={value}
      onBlur={onBlur}
      onChange={onChange}
    >
      <Radio value="customer">Customer</Radio>
      <Radio value="employee">Employee</Radio>
    </RadioGroup>
  )}
/>

@wingkwong
Copy link
Member

which RHF version are you using? To speed up the process, you may share a sandbox instead so that we could look into it faster.

@UltraWelfare
Copy link
Author

which RHF version are you using? To speed up the process, you may share a sandbox instead so that we could look into it faster.

The latest one 7.54.2. I edited my initial post to include the sandbox

@wingkwong wingkwong added 🐛 Type: Bug Something isn't working 📦 Scope : Components Related to the components labels Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 Scope : Components Related to the components 🐛 Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants