Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(elements): Add check for relatedTarget to avoid validation running immediately after unsuccessful form submission #3762

Merged
Show file tree
Hide file tree
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
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
Loading