import {FileProps} from '@givewp/forms/propTypes'; import {__, sprintf} from '@wordpress/i18n'; import {useEffect, useRef} from "react"; /** * @since 4.3.2 manually focus the visible input when error is present. * @since 4.3.0 Add aria-required attribute and file size and type validations. */ export default function File({Label, allowedMimeTypes, maxUploadSize, ErrorMessage, fieldError, description, inputProps}: FileProps) { const FieldDescription = window.givewp.form.templates.layouts.fieldDescription; const {setValue, setError} = window.givewp.form.hooks.useFormContext(); const {name} = inputProps; const ref = useRef(null); useEffect(() => { if (fieldError && ref.current) { ref.current.focus(); } }, [fieldError]); return ( <>