UNPKG

@wordpress/components

Version:
44 lines (43 loc) 1.42 kB
/** * WordPress dependencies */ import { useMergeRefs } from '@wordpress/compose'; import { forwardRef, useRef } from '@wordpress/element'; /** * Internal dependencies */ import { ControlWithError } from '../control-with-error'; import CheckboxControl from '../../checkbox-control'; import { jsx as _jsx } from "react/jsx-runtime"; const UnforwardedValidatedCheckboxControl = ({ required, customValidator, onChange, markWhenOptional, ...restProps }, forwardedRef) => { const validityTargetRef = useRef(null); const mergedRefs = useMergeRefs([forwardedRef, validityTargetRef]); const valueRef = useRef(restProps.checked); return /*#__PURE__*/_jsx(ControlWithError, { required: required, markWhenOptional: markWhenOptional, ref: mergedRefs, customValidator: () => { return customValidator?.(valueRef.current); }, getValidityTarget: () => validityTargetRef.current?.querySelector('input[type="checkbox"]'), children: /*#__PURE__*/_jsx(CheckboxControl, { __nextHasNoMarginBottom: true, onChange: value => { valueRef.current = value; onChange?.(value); } // TODO: Upstream limitation - CheckboxControl doesn't support uncontrolled mode, visually. , ...restProps }) }); }; export const ValidatedCheckboxControl = forwardRef(UnforwardedValidatedCheckboxControl); //# sourceMappingURL=checkbox-control.js.map