Skip to content

Instantly share code, notes, and snippets.

@ptrin
Last active November 13, 2019 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptrin/9d8d9970a7db5cdb1ea35de40310264c to your computer and use it in GitHub Desktop.
Save ptrin/9d8d9970a7db5cdb1ea35de40310264c to your computer and use it in GitHub Desktop.
Formik a11y examples
<ErrorMessage name="firstName">
{msg => (
<div id="firstName-error" className="invalid-feedback">
{msg}
</div>
)}
</ErrorMessage>
<Field
className={classNames("form-control", {
"is-invalid": errors.firstName && touched.firstName
})}
aria-invalid={errors.firstName && touched.firstName ? 'true' : null}
aria-describedby={errors.firstName && touched.firstName ? 'firstName-error' : null}
aria-required="true"
name="firstName"
id="firstName"
/>
innerRef={ (input) => { this.firstNameInput = input }}
componentDidMount() {
this.firstNameInput.focus();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment