Skip to content

Commit

Permalink
fix(elements): Add check for relatedTarget to avoid validation runn…
Browse files Browse the repository at this point in the history
…ing immediately after unsuccessful form submission (#3762)
  • Loading branch information
alexcarpenter authored Jul 18, 2024
1 parent b8e3129 commit c203f8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/plenty-snakes-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/elements": patch
---

Fixes issue where an invalid password field was immediately being refocused after submission causing the validation to run and show the success state.
6 changes: 5 additions & 1 deletion packages/elements/src/react/common/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ const useInput = ({
const onFocus = React.useCallback(
(event: React.FocusEvent<HTMLInputElement>) => {
onFocusProp?.(event);
if (shouldValidatePassword) {
// Check for relatedTarget to avoid validating password when the input
// is programticallly focused after form submission. Avoids the issue
// where an error message would get removed and the success validation
// was shown immediately.
if (shouldValidatePassword && Boolean(event.relatedTarget)) {
validatePassword(event.target.value);
}
},
Expand Down

0 comments on commit c203f8b

Please sign in to comment.