Skip to content

fix: [One-Time Password Field] truncate values ​​that exceed the length when pasting #3551

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nayounsang
Copy link
Contributor

@nayounsang nayounsang commented May 19, 2025

Description

close #3550

  • truncate values exceed the length of collections when pasting
  • There is a concern that SRP may be violated when inserting the corresponding logic into sanitizeValue, and therefore, side effects are a concern, so verification is performed in the paste logic.
  • Test code is skipped because the pasted values ​​of @testing-library/user-event are not assigned to input.

Test with Storybook
Case: paste 124868392

<input autocomplete="off" autocapitalize="off" autocorrect="off" autosave="off" spellcheck="false" readonly="" type="hidden" 
value="124868" 
name="code">

image

@nayounsang nayounsang changed the title fix: truncate values ​​that exceed the length when pasting fix: [One-Time Password Field] truncate values ​​that exceed the length when pasting May 19, 2025
Copy link

changeset-bot bot commented May 19, 2025

🦋 Changeset detected

Latest commit: 6981e19

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@radix-ui/react-one-time-password-field Patch
radix-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chaance
Copy link
Member

chaance commented May 20, 2025

Thanks! Mind adding a unit test to cover this case?

@nayounsang
Copy link
Contributor Author

@chaance I add todo test because user.paste not linked to input data. This is same to the paste test above.

@nayounsang
Copy link
Contributor Author

nayounsang commented May 23, 2025

@chaance

  it('should truncate pasted characters to the number of inputs', async () => {
    const inputs = screen.getAllByRole<HTMLInputElement>('textbox', {
      hidden: false,
    });
    const firstInput = inputs[0]!;
    fireEvent.click(firstInput);
    
    const pasteData = '123456789';
    fireEvent.paste(firstInput, {
      clipboardData: {
        getData: () => pasteData
      }
    });
    
    expect(getInputValues(inputs)).toBe('1,2,3,4,5,6');
  });

I found a way to fix the paste test so that it can simulate fireEvent that are not userEvent.
However, in my philosophy, it seems better to avoid using fireEvent. What should I do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OneTimePasswordField] Paste Exceeding Max Length Is Not Truncated
2 participants