@@ -4,12 +4,17 @@ import { useFieldApi } from '@data-driven-forms/react-form-renderer';
44import { Radio as Pf4Radio } from '@patternfly/react-core' ;
55import FormGroup from '../common/form-group' ;
66
7- const RadioOption = ( { name, option, isDisabled, isReadOnly } ) => {
8- const { input } = useFieldApi ( { name, type : 'radio' , value : option . value } ) ;
7+ const RadioOption = ( { name, option, isDisabled, isReadOnly, radioGroupValue } ) => {
8+ const {
9+ input : { checked, ...input }
10+ } = useFieldApi ( { name, value : option . value } ) ;
911 return (
1012 < Pf4Radio
1113 key = { `${ name } -${ option . value } ` }
1214 { ...input }
15+ isChecked = { radioGroupValue === option . value }
16+ value = { option . value }
17+ onChange = { ( ) => input . onChange ( option . value ) }
1318 label = { option . label }
1419 id = { `${ name } -${ option . value } ` }
1520 aria-label = { option . label }
@@ -22,10 +27,15 @@ RadioOption.propTypes = {
2227 name : PropTypes . string . isRequired ,
2328 option : PropTypes . shape ( { label : PropTypes . node . isRequired , value : PropTypes . any . isRequired } ) . isRequired ,
2429 isDisabled : PropTypes . bool ,
25- isReadOnly : PropTypes . bool
30+ isReadOnly : PropTypes . bool ,
31+ radioGroupValue : PropTypes . any
2632} ;
2733
28- const Radio = ( { name, options, ...props } ) => {
34+ const Radio = ( { name, options, type, ...props } ) => {
35+ /**
36+ * You cannot assign type radio to PF4 radio buttons input. It will break and will not set input value, only checked property
37+ * It has to be reqular input and we have change the radio value manully to the option value
38+ */
2939 const { label, isRequired, helperText, meta, description, hideLabel, input, isReadOnly, isDisabled, id } = useFieldApi ( {
3040 name,
3141 ...props
@@ -41,7 +51,7 @@ const Radio = ({ name, options, ...props }) => {
4151 id = { id || input . name }
4252 >
4353 { options . map ( ( option ) => (
44- < RadioOption key = { option . value } name = { name } option = { option } isReadOnly = { isReadOnly } isDisabled = { isDisabled } />
54+ < RadioOption radioGroupValue = { input . value } key = { option . value } name = { name } option = { option } isReadOnly = { isReadOnly } isDisabled = { isDisabled } />
4555 ) ) }
4656 </ FormGroup >
4757 ) ;
@@ -57,7 +67,8 @@ Radio.propTypes = {
5767 isDisabled : PropTypes . bool ,
5868 id : PropTypes . string ,
5969 name : PropTypes . string . isRequired ,
60- options : PropTypes . arrayOf ( PropTypes . shape ( { label : PropTypes . string , value : PropTypes . any } ) ) . isRequired
70+ options : PropTypes . arrayOf ( PropTypes . shape ( { label : PropTypes . string , value : PropTypes . any } ) ) . isRequired ,
71+ type : PropTypes . any
6172} ;
6273
6374export default Radio ;
0 commit comments