-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[TextField] Implemented masking #3783
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
[TextField] Implemented masking #3783
Conversation
| return outputMask; | ||
| } | ||
|
|
||
| private _extractValueFromMask(maskedValue: string, element: HTMLInputElement | HTMLTextAreaElement): string { |
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.
I don't think you use element any where in this method
| // Check for backspace | ||
| if (key == 8) { | ||
| if (this.props.mask && this.state.maskCursorPosition && this.state.value) { | ||
| if ((event.target as HTMLInputElement).selectionStart >= this.state.maskCursorPosition) { |
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.
I can select multiple characters and still satisfy this condition, but the value will only be set as 1 less than my current value length.
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.
If you select multiple characters and backspace them, the inputChanged event will detect that you deleted a bunch of characters. Like if you ctrl+a and backspace, it will clear any input the user has made and display the empty mask.
| valueIndex < maskedValue.length && | ||
| maskedValue.charAt(valueIndex) != mask.charAt(maskIndex)) { | ||
| skippedChars++; | ||
| valueIndex++; |
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.
Won't it be possible for the valueIndex be 1 higher than you expect since it will increment once this while loop exits? At least if you have text that's something like a_a_a
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.
That is intentional.
…into magellan/textFieldMasking
| import * as React from 'react'; | ||
| /* tslint:enable:no-unused-variable */ | ||
| import { TextField } from 'office-ui-fabric-react/lib/TextField'; | ||
| import { DefaultTextField } from 'office-ui-fabric-react/lib/TextField'; |
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.
Why do you change all of the examples to use DefaultTextField instead of TextField? That doesn't seem right
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.
For the same reason all of the Button examples were changed to use DefaultButton instead of Button.
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.
What about compat, when I use TextField today, will I have to change to DefaultTextfield with this change?
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.
No, just as with button, the TextField component still exists, it will just warn you for using a deprecated component.
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.
@lambertwang I don't really think that's a good idea.
…into magellan/textFieldMasking
| <tr> | ||
| <td> | ||
| <TextField | ||
| <DefaultTextField |
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.
Why are you renaming everything that was TextField to DefaultTextField? That feels counterintuitive.
|
Any updates on this @lambertwang? |
| inputProperties, | ||
| textAreaProperties | ||
| } from '../../Utilities'; | ||
| import { AnimationClassNames } from '../../Styling'; |
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.
unneeded?
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.
Needed.
| /> | ||
| <MaskedTextField | ||
| label='With input mask' | ||
| mask='Phone Number: (999) 999 - 9999' |
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.
I don't understand how this example works. I will try to get a demo from you.
dzearing
left a comment
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.
This is a little confusing, can you demo for me?
…c-react into magellan/textFieldMasking # Conflicts: # packages/office-ui-fabric-react/src/components/ContextualMenu/examples/ContextualMenu.Directional.Example.tsx
…t into magellan/textFieldMasking
…fice-ui-fabric-react into magellan/textFieldMasking
| @@ -0,0 +1,325 @@ | |||
| import * as React from 'react'; | |||
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.
This is missing tests. Needs a bunch of enzyme tests. And probably a snapshot test or two.
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.
Done.
| "changes": [ | ||
| { | ||
| "packageName": "office-ui-fabric-react", | ||
| "comment": "TextField: Inmplemented input masking.", |
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.
typo
dzearing
left a comment
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.
needs test.
…into magellan/textFieldMasking
|
@dzearing @cschleiden Can I get another review? I've made some changes and added enzyme tests for the component. |
…into magellan/textFieldMasking
cliffkoh
left a comment
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.
As Travis CI indicated, your change has a lot of null check failures. Please update your submission to resolve the issues.. I will take a look at your unit tests though.
|
@lambertwang FTFY: lambertwang-zz#1 |
…king Fix build break issues with your PR
cliffkoh
left a comment
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.
@lambertwang You now have a bunch of unused vars errors due to the recent change to tslint :)
The tests look fine. I did not look very closely at other changes besides the test since other reviewers have looked at it so approving for now.
…into magellan/textFieldMasking
* master: DetailsRow: Flexshrink fix (microsoft#4622) [TextField] Implemented masking (microsoft#3783) Applying package updates. ComboBox: Add any event as additional parameter to onChanged callback for saving pending changes (microsoft#4594) Remove usage of Number.NaN (microsoft#4615)
Pull request checklist
$ npm run changeDescription of changes
Implemented input masking (similar to https://www.npmjs.com/package/react-input-mask)
Note: the MaskedTextField is its own component. The original TextField component should be untouched.