@wordpress/components
Version:
UI components for WordPress.
42 lines (41 loc) • 1.32 kB
JavaScript
// packages/components/src/validated-form-controls/components/textarea-control.tsx
import { forwardRef, useRef } from "@wordpress/element";
import { useMergeRefs } from "@wordpress/compose";
import { ControlWithError } from "../control-with-error";
import TextareaControl from "../../textarea-control";
import { jsx as _jsx } from "react/jsx-runtime";
var UnforwardedValidatedTextareaControl = ({
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(TextareaControl, {
__nextHasNoMarginBottom: true,
ref: mergedRefs,
onChange: (value) => {
valueRef.current = value;
onChange?.(value);
},
...restProps
})
});
};
var ValidatedTextareaControl = forwardRef(UnforwardedValidatedTextareaControl);
export {
ValidatedTextareaControl
};
//# sourceMappingURL=textarea-control.js.map