dohomi/react-hook-form-mui

single Radio

Closed this issue · 6 comments

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

hi, i'm missing possiblity to add a single Radio button instead of the whole group
use case: complicated layout when radio group can be applied

Examples 🌈

No response

This seems a rare case. Why not using a single item within the radio group? Seems for me more like to choose a checkbox for it

imagen
my case - radio buttons within table as there can be any other component which can even span over more columns (i must admin i could use a different elements to wrap the controls but chose table for the sake of implementation simplicity)

MUI has it implemented (https://mui.com/material-ui/api/radio/), so i can use it in a standard Controller-render -> Radio composition

I have to suggest that you use your own implementation for this use case, most likely you don't even have to use react-hook-form for this.. otherwise if you do, just run your own implementaion with useForm and use the onChange handler of each Radio to modify the value of your form state, this will be better performance than using useController on each radio. I assume you are not doing any validation so seems like a best solution for your table

i did my own implementation as mentioned including validation, no worries - there's always a way ;) i understand it'd add unnecessary complexity because of a few edge cases

i did my own implementation as mentioned including validation, no worries - there's always a way ;) i understand it'd add unnecessary complexity because of a few edge cases

Great that you find a solution, make sure you dont run too many unnecessary renders with useController if you actually don't need to validate but simply want the final result in your onSubmit handler

I'm not using useController, just having MUI Radio wrapped in Controller component as I need to have it mapped with RHF