UNPKG

@rjsf/antd

Version:

Ant Design theme, fields and widgets for react-jsonschema-form

19 lines 1.78 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { Radio } from 'antd'; import { ariaDescribedByIds, enumOptionsIndexForValue, enumOptionsValueForIndex, optionId, } 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, }) { const { readonlyAsDisabled = true } = formContext; const { enumOptions, enumDisabled, emptyValue } = options; const handleChange = ({ target: { value: nextValue } }) => onChange(enumOptionsValueForIndex(nextValue, enumOptions, emptyValue)); const handleBlur = ({ target }) => onBlur(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)); const handleFocus = ({ target }) => onFocus(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)); const selectedIndexes = enumOptionsIndexForValue(value, enumOptions); return (_jsx(Radio.Group, { disabled: disabled || (readonlyAsDisabled && readonly), id: id, name: id, onChange: !readonly ? handleChange : undefined, onBlur: !readonly ? handleBlur : undefined, onFocus: !readonly ? handleFocus : undefined, value: selectedIndexes, "aria-describedby": ariaDescribedByIds(id), children: Array.isArray(enumOptions) && enumOptions.map((option, i) => (_jsx(Radio, { id: optionId(id, i), name: id, autoFocus: i === 0 ? autofocus : false, disabled: disabled || (Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1), value: String(i), children: option.label }, i))) })); } //# sourceMappingURL=index.js.map