import { FocusEvent } from 'react'; import { Radio, RadioChangeEvent } from 'antd'; import { ariaDescribedByIds, enumOptionsIndexForValue, enumOptionsValueForIndex, optionId, FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, WidgetProps, } from '@rjsf/utils'; /** The `RadioWidget` is a widget for rendering a radio group. * It is typically used with a string property constrained with enum options. * * @param props - The `WidgetProps` for this component */ export default function RadioWidget({ autofocus, disabled, registry, id, htmlName, onBlur, onChange, onFocus, options, readonly, value, }: WidgetProps) { const { formContext } = registry; const { readonlyAsDisabled = true } = formContext as GenericObjectType; const { enumOptions, enumDisabled, emptyValue } = options; const handleChange = ({ target: { value: nextValue } }: RadioChangeEvent) => onChange(enumOptionsValueForIndex(nextValue, enumOptions, emptyValue)); const handleBlur = ({ target }: FocusEvent) => onBlur(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)); const handleFocus = ({ target }: FocusEvent) => onFocus(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)); const selectedIndexes = enumOptionsIndexForValue(value, enumOptions) as string; return ( {Array.isArray(enumOptions) && enumOptions.map((option, i) => ( {option.label} ))} ); }