@piplup/rhf-adaptersmui-materialComponents
MuiRadioElement
A pre-integrated MuiRadioElement component for connecting MUI Radio to React Hook Form.
Import
import { MuiRadioElement } from "@piplup/rhf-adapters/mui-material";Usage
"use client";import FormControlLabel from "@mui/material/FormControlLabel";import Stack from "@mui/material/Stack";import { MuiRadioElement, MuiButtonElement,} from "@piplup/rhf-adapters/mui-material";import { useForm } from "react-hook-form";export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { choice: "" }, }); return ( <form onSubmit={handleSubmit((values) => alert(JSON.stringify(values, null, 2)), )} > <Stack direction="column" spacing={2}> <FormControlLabel control={ <MuiRadioElement name="choice" value="a" checked={(value) => value === "a"} control={control} /> } label="Choice A" /> <FormControlLabel control={ <MuiRadioElement name="choice" value="b" checked={(value) => value === "b"} control={control} /> } label="Choice B" /> <div> <MuiButtonElement control={control} type="submit" variant="contained"> Submit </MuiButtonElement> </div> </Stack> </form> );}"use client";import FormControlLabel from "@mui/material/FormControlLabel";import Stack from "@mui/material/Stack";import { MuiRadioElement, MuiButtonElement,} from "@piplup/rhf-adapters/mui-material";import { FormContainer } from "@piplup/rhf-core";export default function Page() { return ( <FormContainer defaultValues={{ choice: "" }} onSubmit={(values) => alert(JSON.stringify(values, null, 2))} > <Stack direction="column" spacing={2}> <FormControlLabel control={ <MuiRadioElement name="choice" value="a" checked={(value) => value === "a"} /> } label="Choice A" /> <FormControlLabel control={ <MuiRadioElement name="choice" value="b" checked={(value) => value === "b"} /> } label="Choice B" /> <div> <MuiButtonElement type="submit" variant="contained"> Submit </MuiButtonElement> </div> </Stack> </FormContainer> );}Props
Prop
Type
MuiRadioElement supports props of the MUI Radio component, along with additional adapter-specific props. For a complete list of available Radio properties, refer to the MUI API documentation.
The
refis forwarded to the underlying<Radio />component.
Notes
- For custom radio UIs, build on
useMuiRadioAdapter.