@wordpress/components
Version:
UI components for WordPress.
42 lines (41 loc) • 1.27 kB
JavaScript
/**
* WordPress dependencies
*/
import { forwardRef, useRef } from '@wordpress/element';
import { useMergeRefs } from '@wordpress/compose';
/**
* Internal dependencies
*/
import { ControlWithError } from '../control-with-error';
import InputControl from '../../input-control';
import { jsx as _jsx } from "react/jsx-runtime";
const UnforwardedValidatedInputControl = ({
required,
customValidator,
onChange,
markWhenOptional,
...restProps
}, forwardedRef) => {
const validityTargetRef = useRef(null);
const mergedRefs = useMergeRefs([forwardedRef, validityTargetRef]);
const valueRef = useRef(restProps.value);
return /*#__PURE__*/_jsx(ControlWithError, {
required: required,
markWhenOptional: markWhenOptional,
customValidator: () => {
return customValidator?.(valueRef.current);
},
getValidityTarget: () => validityTargetRef.current,
children: /*#__PURE__*/_jsx(InputControl, {
__next40pxDefaultSize: true,
ref: mergedRefs,
onChange: (value, ...args) => {
valueRef.current = value;
onChange?.(value, ...args);
},
...restProps
})
});
};
export const ValidatedInputControl = forwardRef(UnforwardedValidatedInputControl);
//# sourceMappingURL=input-control.js.map