Files
EMS-ESP32/interface/src/components/inputs/ValidatedTextField.tsx
2025-10-19 16:23:53 +02:00

32 lines
733 B
TypeScript

import type { FC } from 'react';
import { FormHelperText, TextField } from '@mui/material';
import type { TextFieldProps } from '@mui/material';
import type { ValidateFieldsError } from 'async-validator';
interface ValidatedFieldProps {
fieldErrors?: ValidateFieldsError;
name: string;
}
export type ValidatedTextFieldProps = ValidatedFieldProps & TextFieldProps;
const ValidatedTextField: FC<ValidatedTextFieldProps> = ({
fieldErrors,
...rest
}) => {
const errors = fieldErrors?.[rest.name];
return (
<>
<TextField error={!!errors} {...rest} />
{errors?.map((e) => (
<FormHelperText key={e.message}>{e.message}</FormHelperText>
))}
</>
);
};
export default ValidatedTextField;