-
Notifications
You must be signed in to change notification settings - Fork 69
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
[BD-46] feat: added FormControl input mask #2626
Conversation
✅ Deploy Preview for paragon-openedx ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Thanks for the pull request, @PKulkoRaccoonGang! When this pull request is ready, tag your edX technical lead. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
3b88d2e
to
029f3d9
Compare
62b9d12
to
4687fed
Compare
4687fed
to
9ef3e26
Compare
a236cc6
to
c1c1a1e
Compare
src/Form/form-control.mdx
Outdated
## 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 /> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected, thanks
src/Form/form-control.mdx
Outdated
<h3>Phone</h3> | ||
<Form.Group> | ||
<Form.Control | ||
inputMask="+{1}(000)000-00-00" |
There was a problem hiding this comment.
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.
src/Form/form-control.mdx
Outdated
<h3>Date</h3> | ||
<Form.Group> | ||
<Form.Control | ||
inputMask={Date} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
src/Form/form-control.mdx
Outdated
</>), | ||
price: ( | ||
<> | ||
<h3>Course prise</h3> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "Price"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
src/Form/form-control.mdx
Outdated
<> | ||
<Form.Group> | ||
<Form.Control | ||
inputMask="+{1}(000)000-00-00" |
There was a problem hiding this comment.
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.
src/Form/tests/FormControl.test.jsx
Outdated
|
||
act(() => { | ||
const input = screen.getByTestId('form-control-with-mask'); | ||
userEvent.type(input, '1234567890'); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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:
- When should I use act() in react-testing-library?
- Internal implementation
- 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.
We have several options for further action:
- Apply now the solution with an override of the
@testing-library/dom
package (with version9.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 inact
userEvent
. I have verified this in the Tabs component and in my current case (FormControl).
"overrides": {
"@testing-library/dom": "9.3.3"
}
- 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.
There was a problem hiding this comment.
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.
src/Form/tests/FormControl.test.jsx
Outdated
render(<Component isClearValue />); | ||
|
||
const input = screen.getByTestId('form-control-with-mask'); | ||
fireEvent.change(input, { target: { value: '1234567890' } }); |
There was a problem hiding this comment.
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.
🎉 This PR is included in version 21.9.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 22.0.0-alpha.20 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Issue: #2458
Deploy Preview
Form.Control component
Merge Checklist
example
app?wittjeff
andadamstankiewicz
as reviewers on this PR.Post-merge Checklist