Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
feat(clerk-js): Enhanced password manager detection#6311
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/clerk-js': patch | ||
| --- | ||
| Enhanced detection of password manangers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 70 additions & 4 deletions
74 packages/clerk-js/src/ui/elements/__tests__/CodeControl.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -328,19 +328,85 @@ describe('CodeControl', () => { | ||
| // Simulate autofill with mixed characters | ||
| if (hiddenInput) { | ||
| fireEvent.change(hiddenInput, { target: { value: '1a2b3c4d5e6f' } }); | ||
| fireEvent.change(hiddenInput, { target: { value: '1a2b3c' } }); | ||
| } | ||
| await waitFor(() => { | ||
| expect(visibleInputs[0]).toHaveValue('1'); | ||
| expect(visibleInputs[1]).toHaveValue('2'); | ||
| expect(visibleInputs[2]).toHaveValue('3'); | ||
| expect(visibleInputs[3]).toHaveValue('4'); | ||
| expect(visibleInputs[4]).toHaveValue('5'); | ||
| expect(visibleInputs[5]).toHaveValue('6'); | ||
| expect(visibleInputs[3]).toHaveValue(''); | ||
| expect(visibleInputs[4]).toHaveValue(''); | ||
| expect(visibleInputs[5]).toHaveValue(''); | ||
| }); | ||
| }); | ||
| it('has proper password manager attributes for detection', async () => { | ||
| const { wrapper } = await createFixtures(); | ||
| const onCodeEntryFinished = vi.fn(); | ||
| const Component = createOTPComponent(onCodeEntryFinished); | ||
| const { container } = render(<Component />, { wrapper }); | ||
| const hiddenInput = container.querySelector('[data-otp-hidden-input]'); | ||
| // Verify critical attributes for detection | ||
| expect(hiddenInput).toHaveAttribute('autocomplete', 'one-time-code'); | ||
| expect(hiddenInput).toHaveAttribute('inputmode', 'numeric'); | ||
| expect(hiddenInput).toHaveAttribute('pattern', '[0-9]{6}'); | ||
| expect(hiddenInput).toHaveAttribute('minlength', '6'); | ||
| expect(hiddenInput).toHaveAttribute('maxlength', '6'); | ||
| expect(hiddenInput).toHaveAttribute('name', 'otp'); | ||
| expect(hiddenInput).toHaveAttribute('id', 'otp-input'); | ||
| expect(hiddenInput).toHaveAttribute('data-otp-input'); | ||
tmilewski marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| expect(hiddenInput).toHaveAttribute('role', 'textbox'); | ||
| expect(hiddenInput).toHaveAttribute('aria-label', 'One-time password input for password managers'); | ||
| expect(hiddenInput).toHaveAttribute('aria-hidden', 'true'); | ||
| expect(hiddenInput).toHaveAttribute('data-testid', 'otp-input'); | ||
| }); | ||
| it('handles focus redirection from hidden input to visible inputs', async () => { | ||
| const { wrapper } = await createFixtures(); | ||
| const onCodeEntryFinished = vi.fn(); | ||
| const Component = createOTPComponent(onCodeEntryFinished); | ||
| const { container } = render(<Component />, { wrapper }); | ||
| const hiddenInput = container.querySelector('[data-otp-hidden-input]') as HTMLInputElement; | ||
| const visibleInputs = container.querySelectorAll('[data-otp-segment]'); | ||
| // Focus the hidden input (simulating password manager behavior) | ||
| hiddenInput.focus(); | ||
| await waitFor(() => { | ||
| // Should redirect focus to first visible input | ||
| expect(visibleInputs[0]).toHaveFocus(); | ||
| }); | ||
| }); | ||
| it('maintains accessibility with proper ARIA attributes', async () => { | ||
| const { wrapper } = await createFixtures(); | ||
| const onCodeEntryFinished = vi.fn(); | ||
| const Component = createOTPComponent(onCodeEntryFinished); | ||
| const { container } = render(<Component />, { wrapper }); | ||
| const hiddenInput = container.querySelector('[data-otp-hidden-input]'); | ||
| const inputContainer = container.querySelector('[role="group"]'); | ||
| const instructions = container.querySelector('#otp-instructions'); | ||
| // Verify ARIA setup - some attributes might be filtered by the Input component | ||
| expect(hiddenInput).toHaveAttribute('aria-hidden', 'true'); | ||
| expect(inputContainer).toHaveAttribute('aria-describedby', 'otp-instructions'); | ||
| expect(instructions).toHaveTextContent('Enter the 6-digit verification code'); | ||
| // Check for any aria-describedby attribute (it might be there but not exactly as expected) | ||
| const ariaDescribedBy = hiddenInput?.getAttribute('aria-describedby'); | ||
| if (ariaDescribedBy) { | ||
| expect(ariaDescribedBy).toBe('otp-instructions'); | ||
| } | ||
| }); | ||
| it('focuses first visible input when hidden input is focused', async () => { | ||
| const { wrapper } = await createFixtures(); | ||
| const onCodeEntryFinished = vi.fn(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.