UNPKG

@wordpress/components

Version:
41 lines (40 loc) 1.29 kB
// packages/components/src/validated-form-controls/components/radio-control.tsx import { useMergeRefs } from "@wordpress/compose"; import { forwardRef, useRef } from "@wordpress/element"; import { ControlWithError } from "../control-with-error"; import RadioControl from "../../radio-control"; import { jsx as _jsx } from "react/jsx-runtime"; var UnforwardedValidatedRadioControl = ({ required, onValidate, customValidity, onChange, markWhenOptional, ...restProps }, forwardedRef) => { const validityTargetRef = useRef(null); const mergedRefs = useMergeRefs([forwardedRef, validityTargetRef]); const valueRef = useRef(restProps.selected); return /* @__PURE__ */ _jsx(ControlWithError, { required, markWhenOptional, ref: mergedRefs, onValidate: () => { return onValidate?.(valueRef.current); }, customValidity, getValidityTarget: () => validityTargetRef.current?.querySelector('input[type="radio"]'), children: /* @__PURE__ */ _jsx(RadioControl, { onChange: (value) => { valueRef.current = value; onChange?.(value); }, ...restProps }) }); }; var ValidatedRadioControl = forwardRef(UnforwardedValidatedRadioControl); export { ValidatedRadioControl }; //# sourceMappingURL=radio-control.js.map