Skip to content

Commit

Permalink
Merge pull request #190 from zrajnis/remove-focus-on-submission-fail
Browse files Browse the repository at this point in the history
remove focus on submission failure
  • Loading branch information
zapov authored Oct 21, 2022
2 parents d4826a4 + 29be083 commit fd9fb29
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion typescript-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@
"test:watch": "react-scripts test --env=jsdom"
},
"source": "src/index.ts",
"version": "1.9.5"
"version": "1.9.6"
}
7 changes: 1 addition & 6 deletions typescript-react/src/components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ const genericError = 'Please correct all the required fields.';
const scrollToFirstError = (errors: FormErrors<FormData, ErrorType> | undefined = {}) => {
const fieldNames = deepKeys(errors, true);

// select library and datepicker don't have a name attribute on input, so the only way to target them is through data-qa-element-id
// data-qa-element-id has an unfortunate naming, and changing it now would be a breaking change, would be much prettier if it was data-element-id
// adding another data attribute would just duplicate stuff, as it would have the same value as data-qa-element-id
for (const fieldName of fieldNames) {
const dataQaEl = `[data-qa-element-id="${fieldName}"]`;
const el = document.querySelectorAll(`[name="${fieldName}"], ${dataQaEl} input, input${dataQaEl}`)[0] as HTMLElement;
const el = document.querySelectorAll(`[name="${fieldName}"]`)[0] as HTMLElement;

if (el) {
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
el.focus({ preventScroll: true });
break;
}
}
Expand Down

0 comments on commit fd9fb29

Please sign in to comment.