import React, { ReactElement } from "react"; export interface FieldProps { label: string; required: boolean; widget: ReactElement; helpText?: string; displayOptions?: { focusOnMount?: boolean; hideRequiredAsterisk?: boolean; }; errors: string[]; } function Field({ label, required, widget, helpText, displayOptions, errors, }: FieldProps): ReactElement { // Focus on mount const wrapperRef = React.useRef(null); React.useEffect(() => { if (displayOptions?.focusOnMount && wrapperRef.current) { const inputElement = wrapperRef.current.querySelector("input"); if (inputElement) { inputElement.focus(); } } }, [displayOptions?.focusOnMount]); return (
{widget} {helpText &&
}
{!!errors.length && (
    {errors.map((error) => (
  • {error}
  • ))}
)}
); } export default Field;