Skip to content
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

[BD-46] feat: added FormControl input mask #2626

Merged

Conversation

PKulkoRaccoonGang
Copy link
Contributor

@PKulkoRaccoonGang PKulkoRaccoonGang commented Sep 15, 2023

Description

  • added FormControl input mask.

Issue: #2458

Deploy Preview

Form.Control component

Merge Checklist

  • If your update includes visual changes, have they been reviewed by a designer? Send them a link to the Netlify deploy preview, if applicable.
  • Does your change adhere to the documented style conventions?
  • Do any prop types have missing descriptions in the Props API tables in the documentation site (check deploy preview)?
  • Were your changes tested using all available themes (see theme switcher in the header of the deploy preview, under the "Settings" icon)?
  • Were your changes tested in the example app?
  • Is there adequate test coverage for your changes?
  • Consider whether this change needs to reviewed/QA'ed for accessibility (a11y). If so, please add wittjeff and adamstankiewicz as reviewers on this PR.

Post-merge Checklist

  • Verify your changes were released to NPM at the expected version.
  • If you'd like, share your contribution in #show-and-tell.
  • 🎉 🙌 Celebrate! Thanks for your contribution.

@netlify
Copy link

netlify bot commented Sep 15, 2023

Deploy Preview for paragon-openedx ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit d6dc0e3
🔍 Latest deploy log https://app.netlify.com/sites/paragon-openedx/deploys/655de87e89bb540008252f8a
😎 Deploy Preview https://deploy-preview-2626--paragon-openedx.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@openedx-webhooks openedx-webhooks added the blended PR is managed through 2U's blended developmnt program label Sep 15, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Sep 15, 2023

Thanks for the pull request, @PKulkoRaccoonGang!

When this pull request is ready, tag your edX technical lead.

@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (484a30e) 92.82% compared to head (d6dc0e3) 92.83%.
Report is 57 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2626   +/-   ##
=======================================
  Coverage   92.82%   92.83%           
=======================================
  Files         235      235           
  Lines        4237     4241    +4     
  Branches     1029     1030    +1     
=======================================
+ Hits         3933     3937    +4     
  Misses        300      300           
  Partials        4        4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@PKulkoRaccoonGang PKulkoRaccoonGang force-pushed the Peter_Kulko/form-control-mask branch 3 times, most recently from 3b88d2e to 029f3d9 Compare September 18, 2023 10:48
@PKulkoRaccoonGang PKulkoRaccoonGang marked this pull request as ready for review September 18, 2023 10:49
src/Form/FormControl.jsx Outdated Show resolved Hide resolved
src/Form/FormControl.jsx Outdated Show resolved Hide resolved
src/Form/tests/FormControl.test.jsx Outdated Show resolved Hide resolved
@PKulkoRaccoonGang PKulkoRaccoonGang force-pushed the Peter_Kulko/form-control-mask branch from 62b9d12 to 4687fed Compare September 18, 2023 16:11
@PKulkoRaccoonGang PKulkoRaccoonGang force-pushed the Peter_Kulko/form-control-mask branch from 4687fed to 9ef3e26 Compare September 18, 2023 19:18
src/Form/FormControl.jsx Outdated Show resolved Hide resolved
src/Form/FormControl.jsx Outdated Show resolved Hide resolved
@PKulkoRaccoonGang PKulkoRaccoonGang force-pushed the Peter_Kulko/form-control-mask branch from a236cc6 to c1c1a1e Compare October 20, 2023 09:29
## Input masks
Paragon uses the [react-imask](https://www.npmjs.com/package/react-imask) library,
which allows you to add masks of different types for inputs.
To create your own mask, you need to pass the required mask pattern (`+{1}(000)000-00-00`) to the `inputMask` property. <br />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The US-based example phone number mask should likely be +{1} (000) 000-0000 so that phone numbers are formatted like +1 (555) 555-5555, which is typical for a US-based phone number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected, thanks

<h3>Phone</h3>
<Form.Group>
<Form.Control
inputMask="+{1}(000)000-00-00"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The US-based example phone number mask should likely be +{1} (000) 000-0000 so that phone numbers are formatted like +1 (555) 555-5555, which is typical for a US-based phone number.

<h3>Date</h3>
<Form.Group>
<Form.Control
inputMask={Date}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit curious about this one; it appears it doesn't let users input months without leading zeros? For example, when trying to type in June 10, I type 6 for the month, but it doesn't accept any input until I add a leading zero first.

Beyond this, I'm also wondering if we should keep the date input mask example of these examples given the Form.Control can be used specifically with a date picker input type.

Copy link
Contributor Author

@PKulkoRaccoonGang PKulkoRaccoonGang Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that this is a good solution if the mask requires entering a zero before the month.
But this example seems redundant since we have a better use case (Form.Control).
Removed this example

</>),
price: (
<>
<h3>Course prise</h3>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "Price"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected

<>
<Form.Group>
<Form.Control
inputMask="+{1}(000)000-00-00"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The US-based example phone number mask should likely be +{1} (000) 000-0000 so that phone numbers are formatted like +1 (555) 555-5555, which is typical for a US-based phone number.


act(() => {
const input = screen.getByTestId('form-control-with-mask');
userEvent.type(input, '1234567890');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[curious] generally, userEvent.* functions are called outside of act since the userEvent.* functions are already wrapped with act (example source).

Copy link
Contributor Author

@PKulkoRaccoonGang PKulkoRaccoonGang Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamstankiewicz thank you for bringing this issue to our attention 👍

At the moment we have a lot of similar examples of wrapping in act userEvent in Paragon. I've looked into several interesting sources (including the one you shared), this is really an unnecessary solution, here are some confirmations:

  1. When should I use act() in react-testing-library?
  2. Internal implementation
  3. Is wrapping with act now required?

My solution is based on Is wrapping with act now required?. As it turned out, we have differences in the @testing-library/dom subdependency in the versions of the @testing-library/[email protected] and @testing-library/[email protected] libraries. A dependency conflict negatively affects the performance of the userEvent and we see a warning after running tests.

image

We have several options for further action:

  1. Apply now the solution with an override of the @testing-library/dom package (with version 9.3.3). This way we will get rid of the problem of displaying warnings in the console and our tests will be cleaner. This solution can be developed in a separate task, where we remove the wrapping in act userEvent. I have verified this in the Tabs component and in my current case (FormControl).
  "overrides": {
    "@testing-library/dom": "9.3.3"
  }
image
  1. Make these changes and “synchronize” the @testing-library/dom subdependency in @testing-library/react and @testing-library/user-event in the pull request for updating to React 18. So It is quite likely that we will not have to do this since we will update the versions of @testing-library/react and @testing-library/user-event. But we cannot predict whether @testing-library/dom versions will change in the future. Therefore, the override option seems workable.

An article about dependency overriding, in which we can make sure that our intentions are correct:

There should only be a single copy of a given dependency in our tree, but npm's dependency resolution will result in a duplicate due to version conflicts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging into, this @PKulkoRaccoonGang! TIL that @testing-library/dom has to be synchronized :) I agree with your synopsis/options; interesting that I'm not sure this has come up before in MFEs that use RTL. But I agree the overrides is sufficient to hold over until the React 18 upgrade.

render(<Component isClearValue />);

const input = screen.getByTestId('form-control-with-mask');
fireEvent.change(input, { target: { value: '1234567890' } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[curious] Why use userEvent.type but fireEvent.change here? Ideally, we could rely on userEvent to more closely mimic real user behavior.

@PKulkoRaccoonGang PKulkoRaccoonGang marked this pull request as draft November 21, 2023 14:05
@PKulkoRaccoonGang PKulkoRaccoonGang marked this pull request as ready for review November 22, 2023 11:44
@adamstankiewicz adamstankiewicz merged commit 8f2c06c into openedx:master Dec 8, 2023
10 checks passed
@openedx-semantic-release-bot

🎉 This PR is included in version 21.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@openedx-semantic-release-bot

🎉 This PR is included in version 22.0.0-alpha.20 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blended PR is managed through 2U's blended developmnt program released on @alpha released
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants