[Radio group] Better control of input element #1674
randallmlough
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
@randallmlough Obviously not as easy as using the import { RadioGroup } from "@headlessui/react";
import { Controller, useForm } from "react-hook-form";
const MyForm = () => {
const { control } = useForm();
return (
<Controller
control={control}
defaultValue="default"
name="fieldName"
rules={{
required: "This field is required",
}}
render={({ field }) => (
<RadioGroup
{...field}
// Any other non-controlled props here
>
<RadioGroup.Label>Role</RadioGroup.Label>
{/* RadioGroup option fields */}
</RadioGroup>
)}
/>
);
}; Hope this helps! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
IMO it should be possible to have more control of the hidden input element. Per your documentation by adding in a name field in the group a hidden input field is created; which works, but that doesn't serve a lot of value when you need to reference the state of that input.
For example, if you trying to use something like react hook forms you need to pass their
register
function to your controlled component, but that's not doable atm for RadioGroups.Possible solution ideas:
Beta Was this translation helpful? Give feedback.
All reactions