formik-mui
Version:
34 lines (33 loc) • 911 B
JavaScript
import { jsx } from "react/jsx-runtime";
import MuiTextField from "@mui/material/TextField";
import { getIn } from "formik";
function fieldToTextField({
disabled,
field: { onBlur: fieldOnBlur, ...field },
form: { isSubmitting, touched, errors },
onBlur,
helperText,
...props
}) {
const fieldError = getIn(errors, field.name);
const showError = getIn(touched, field.name) && !!fieldError;
return {
error: showError,
helperText: showError ? fieldError : helperText,
disabled: disabled ?? isSubmitting,
onBlur: onBlur ?? function(e) {
fieldOnBlur(e ?? field.name);
},
...field,
...props
};
}
function TextField({ children, ...props }) {
return /* @__PURE__ */ jsx(MuiTextField, { ...fieldToTextField(props), children });
}
TextField.displayName = "FormikMaterialUITextField";
export {
TextField,
fieldToTextField
};
//# sourceMappingURL=TextField.js.map