UNPKG

@wordpress/components

Version:
43 lines (42 loc) 1.31 kB
// packages/components/src/validated-form-controls/components/text-control.tsx import { useMergeRefs } from "@wordpress/compose"; import { forwardRef, useRef } from "@wordpress/element"; import { ControlWithError } from "../control-with-error"; import TextControl from "../../text-control"; import { jsx as _jsx } from "react/jsx-runtime"; var UnforwardedValidatedTextControl = ({ required, onValidate, customValidity, onChange, markWhenOptional, ...restProps }, forwardedRef) => { const validityTargetRef = useRef(null); const mergedRefs = useMergeRefs([forwardedRef, validityTargetRef]); const valueRef = useRef(restProps.value); return /* @__PURE__ */ _jsx(ControlWithError, { required, markWhenOptional, onValidate: () => { return onValidate?.(valueRef.current); }, customValidity, getValidityTarget: () => validityTargetRef.current, children: /* @__PURE__ */ _jsx(TextControl, { __next40pxDefaultSize: true, __nextHasNoMarginBottom: true, ref: mergedRefs, onChange: (value) => { valueRef.current = value; onChange?.(value); }, ...restProps }) }); }; var ValidatedTextControl = forwardRef(UnforwardedValidatedTextControl); export { ValidatedTextControl }; //# sourceMappingURL=text-control.js.map