|
1 | 1 | import { ChangeEvent, FocusEvent } from 'react' |
2 | 2 | import { |
| 3 | + enumOptionsIsSelected, |
3 | 4 | enumOptionsValueForIndex, |
4 | 5 | FormContextType, |
5 | 6 | RJSFSchema, |
@@ -37,28 +38,41 @@ export default function RadioWidget< |
37 | 38 | const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) => |
38 | 39 | onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue)) |
39 | 40 |
|
| 41 | + const radioValues = Array.isArray(value) ? value : [value] |
40 | 42 | const inline = Boolean(options && options.inline) |
41 | | - |
| 43 | + console.log(value, options) |
42 | 44 | return ( |
43 | 45 | <div style={{ marginTop: '1rem', marginBottom: '-1rem' }}> |
44 | 46 | <RadioButtons |
45 | 47 | options={ |
46 | 48 | (options && |
47 | | - options.enumOptions?.map((option) => ({ |
48 | | - label: ( |
49 | | - <LabelWithHelp |
50 | | - helpText={ |
51 | | - uiSchema !== undefined ? uiSchema['ui:help'] : undefined |
52 | | - } |
53 | | - > |
54 | | - {option.label} |
55 | | - </LabelWithHelp> |
56 | | - ), |
57 | | - nativeInputProps: { |
58 | | - checked: value === option.value, |
59 | | - onChange: (e) => onChange(option.value), |
60 | | - }, |
61 | | - }))) || |
| 49 | + options.enumOptions?.map((option) => { |
| 50 | + const checked = enumOptionsIsSelected<S>( |
| 51 | + option.value, |
| 52 | + radioValues, |
| 53 | + ) |
| 54 | + const itemDisabled = |
| 55 | + Array.isArray(enumDisabled) && |
| 56 | + enumDisabled.indexOf(option.value) !== -1 |
| 57 | + |
| 58 | + return { |
| 59 | + label: ( |
| 60 | + <LabelWithHelp |
| 61 | + helpText={ |
| 62 | + uiSchema !== undefined ? uiSchema['ui:help'] : undefined |
| 63 | + } |
| 64 | + > |
| 65 | + {option.label} |
| 66 | + </LabelWithHelp> |
| 67 | + ), |
| 68 | + nativeInputProps: { |
| 69 | + checked, |
| 70 | + disabled: itemDisabled, |
| 71 | + onChange: (e) => onChange(option.value), |
| 72 | + value: option.value, |
| 73 | + }, |
| 74 | + } |
| 75 | + })) || |
62 | 76 | [] |
63 | 77 | } |
64 | 78 | /> |
|
0 commit comments