Skip to content

Commit ac95d69

Browse files
committed
fix(ui): Stop SignIn switching back to phone on the first "Use email" click
1 parent 89f510d commit ac95d69

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/ui': patch
3+
---
4+
5+
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.

‎packages/ui/src/components/SignIn/SignInStart.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ function SignInStartInternal(): JSX.Element {
168168
// When the captcha escalates to an interactive challenge, spotlight it by collapsing/inerting the
169169
// rest of the card (see the descriptors.main column below).
170170
const [captchaIsInteractive, setCaptchaIsInteractive] = useState(false);
171-
const textIdentifierField = useFormControl('identifier', initialValues[identifierAttribute] || '', {
171+
// Never seed the text field with the phone number, as a leading "+" would switch back to the phone field.
172+
const textIdentifierInitialValue = identifierAttribute === 'phone_number' ? '' : initialValues[identifierAttribute];
173+
const textIdentifierField = useFormControl('identifier', textIdentifierInitialValue || '', {
172174
...currentIdentifier,
173175
isRequired: true,
174176
transformer: value => value.trim(),

‎packages/ui/src/components/SignIn/__tests__/SignInStart.test.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,19 @@ describe('SignInStart', () => {
705705
screen.getByDisplayValue(/691 1111111/i);
706706
});
707707

708+
it('switches to the email field on the first click when phoneNumber is prefilled', async () => {
709+
const { wrapper, props } = await createFixtures(f => {
710+
f.withEmailAddress();
711+
f.withPhoneNumber();
712+
});
713+
props.setProps({ initialValues: { phoneNumber: '+306911111111' } });
714+
715+
render(<SignInStart />, { wrapper });
716+
fireEvent.click(screen.getByText(/use email/i));
717+
718+
expect(screen.getByRole('textbox', { name: /email address/i })).toHaveValue('');
719+
});
720+
708721
it('prefills the username field with the correct initial value', async () => {
709722
const { wrapper, props } = await createFixtures(f => {
710723
f.withUsername();

0 commit comments

Comments
 (0)