@etsoo/materialui
Version:
TypeScript Material-UI Implementation
29 lines (28 loc) • 1.12 kB
JavaScript
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import React from "react";
import { InputField } from "../InputField";
import Typography from "@mui/material/Typography";
/**
* Textarea field creator
* type: textarea
* @returns Component
*/
export const FieldTexarea = ({ field, mref, onChange, defaultValue }) => {
// Ref
const inputRef = React.useRef();
const getValue = () => inputRef.current?.value;
const setValue = (value) => {
if (inputRef.current)
inputRef.current.value = `${value ?? ""}`;
};
React.useImperativeHandle(mref, () => ({
getValue,
setValue
}));
// Name
const name = field.name;
if (!name) {
return (_jsxs(Typography, { children: ["No name for FieldTextarea ", JSON.stringify(field)] }));
}
return (_jsx(InputField, { label: field.label ?? "", helperText: field.helperText, name: name, fullWidth: true, multiline: true, rows: 4, inputProps: { maxLength: 1280 }, inputRef: inputRef, defaultValue: defaultValue, onChange: () => onChange(name, getValue()), ...field.mainSlotProps }));
};