import { FocusEvent } from 'react'; import Radio, { RadioChangeEvent } from 'antd/lib/radio'; 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, formContext, id, onBlur, onChange, onFocus, options, readonly, value, }: WidgetProps) { 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.value, enumOptions, emptyValue)); const handleFocus = ({ target }: FocusEvent) => onFocus(id, enumOptionsValueForIndex(target.value, enumOptions, emptyValue)); const selectedIndexes = enumOptionsIndexForValue(value, enumOptions) as string; return ( (id)} > {Array.isArray(enumOptions) && enumOptions.map((option, i) => ( {option.label} ))} ); }