Search code examples
reactjsradio-buttonmaterial-uirequired

Is there any way to make React Material-UI radio buttons required


I'm new at React JS. currently I'm using Material-UI for building small reusable components. Is there any way to make Material-UI radio buttons required?

like an input field showing "This field is required" text when empty


Solution

  • You can use name property and add the required property to radio component (change the values to your value property):

    <RadioGroup name="nameRadio" value={''}>
        <FormControlLabel
              value={'value1'}
              control={<Radio required={true} />}
              label={'Label 1'}
            />
         <FormControlLabel
              value={'value2'}
              control={<Radio required={true} />}
              label={'Label 2'}
            />
      </RadioGroup>