Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/formik/src/Formik.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export function useFormik<Values extends FormikValues = FormikValues>({
validateFormWithHighPriority(initialValues.current);
}
}
}
}}
}, [
enableReinitialize,
props.initialValues,
Expand Down Expand Up @@ -915,6 +915,13 @@ export function useFormik<Values extends FormikValues = FormikValues>({
onChange: handleChange,
onBlur: handleBlur,
};

// Add aria-invalid attribute with value 'true' when field has an error
const error = getIn(state.errors, name);
if (error && getIn(state.touched, name)) {
field['aria-invalid'] = 'true';
}

if (isAnObject) {
const {
type,
Expand Down Expand Up @@ -942,7 +949,7 @@ export function useFormik<Values extends FormikValues = FormikValues>({
}
return field;
},
[handleBlur, handleChange, state.values]
[handleBlur, handleChange, state.values, state.errors, state.touched]
);

const dirty = React.useMemo(
Expand Down Expand Up @@ -1216,4 +1223,4 @@ function useEventCallback<T extends (...args: any[]) => any>(fn: T): T {
(...args: any[]) => ref.current.apply(void 0, args),
[]
) as T;
}
}