import { type FormContextType, type RJSFSchema, type StrictRJSFSchema, type WidgetProps, ariaDescribedByIds, enumOptionsIsSelected, enumOptionsValueForIndex, optionId } from "@rjsf/utils"; import { type FocusEvent, useCallback } from "react"; /** 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 */ function RadioWidget< T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any >({ options, value, required, disabled, readonly, autofocus = false, onBlur, onFocus, onChange, id }: WidgetProps) { const { enumOptions, enumDisabled, inline, emptyValue } = options; const handleBlur = useCallback( ({ target: { value } }: FocusEvent) => onBlur(id, enumOptionsValueForIndex(value, enumOptions, emptyValue)), [onBlur, id] ); const handleFocus = useCallback( ({ target: { value } }: FocusEvent) => onFocus(id, enumOptionsValueForIndex(value, enumOptions, emptyValue)), [onFocus, id] ); return (
{Array.isArray(enumOptions) && enumOptions.map((option, i) => { const checked = enumOptionsIsSelected(option.value, value); const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1; const disabledCls = disabled || itemDisabled || readonly ? "disabled" : ""; const handleChange = () => onChange(option.value); const radio = ( // biome-ignore lint/correctness/useJsxKeyInIterable: (id)} /> {option.label} ); return inline ? ( ) : (
); })}
); } export default RadioWidget;