Skip to content

Commit

Permalink
chore(clerk-js): Preserve password input focus on error (#4240)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcarpenter authored Sep 27, 2024
1 parent 40bf962 commit 7f87391
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-plants-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/clerk-js": patch
---

Maintain focus on password input after error during sign in flow.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const usePasswordControl = (props: SignInFactorOnePasswordProps) => {

export const SignInFactorOnePasswordCard = (props: SignInFactorOnePasswordProps) => {
const { onShowAlternativeMethodsClick, onPasswordPwned } = props;
const passwordInputRef = React.useRef<HTMLInputElement>(null);
const card = useCardState();
const { setActive } = useClerk();
const signIn = useCoreSignIn();
Expand Down Expand Up @@ -87,6 +88,8 @@ export const SignInFactorOnePasswordCard = (props: SignInFactorOnePasswordProps)
}

handleError(err, [passwordControl], card.setError);

setTimeout(() => passwordInputRef.current?.focus(), 0);
});
};

Expand Down Expand Up @@ -129,6 +132,7 @@ export const SignInFactorOnePasswordCard = (props: SignInFactorOnePasswordProps)
<Form.ControlRow elementId={passwordControl.id}>
<Form.PasswordInput
{...passwordControl.props}
ref={passwordInputRef}
autoFocus
/>
</Form.ControlRow>
Expand Down

0 comments on commit 7f87391

Please sign in to comment.