Skip to content
Open
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/sign-in-phone-prefill-email-toggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/ui': patch
---

Fix `<SignIn />` switching back to the phone number field on the first "Use email" click when `initialValues.phoneNumber` is set. The prefilled phone number no longer ends up in the email field.
3 changes: 2 additions & 1 deletion packages/ui/src/components/SignIn/SignInStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ function SignInStartInternal(): JSX.Element {
// When the captcha escalates to an interactive challenge, spotlight it by collapsing/inerting the
// rest of the card (see the descriptors.main column below).
const [captchaIsInteractive, setCaptchaIsInteractive] = useState(false);
const textIdentifierField = useFormControl('identifier', initialValues[identifierAttribute] || '', {
const textIdentifierInitialValue = identifierAttribute === 'phone_number' ? '' : initialValues[identifierAttribute];
const textIdentifierField = useFormControl('identifier', textIdentifierInitialValue || '', {
...currentIdentifier,
isRequired: true,
transformer: value => value.trim(),
Expand Down
13 changes: 13 additions & 0 deletions packages/ui/src/components/SignIn/__tests__/SignInStart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,19 @@ describe('SignInStart', () => {
screen.getByDisplayValue(/691 1111111/i);
});

it('switches to the email field on the first click when phoneNumber is prefilled', async () => {
const { wrapper, props } = await createFixtures(f => {
f.withEmailAddress();
f.withPhoneNumber();
});
props.setProps({ initialValues: { phoneNumber: '+306911111111' } });

render(<SignInStart />, { wrapper });
fireEvent.click(screen.getByText(/use email/i));

expect(screen.getByRole('textbox', { name: /email address/i })).toHaveValue('');
});

it('prefills the username field with the correct initial value', async () => {
const { wrapper, props } = await createFixtures(f => {
f.withUsername();
Expand Down