Skip to content

Conversation

@lambertwang-zz
Copy link

@lambertwang-zz lambertwang-zz commented Jan 24, 2018

Pull request checklist

Description 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.

return outputMask;
}

private _extractValueFromMask(maskedValue: string, element: HTMLInputElement | HTMLTextAreaElement): string {
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Author

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++;
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

That is intentional.

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';
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Member

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.

<tr>
<td>
<TextField
<DefaultTextField
Copy link
Member

@dzearing dzearing Feb 7, 2018

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.

@jordandrako
Copy link
Contributor

Any updates on this @lambertwang?

inputProperties,
textAreaProperties
} from '../../Utilities';
import { AnimationClassNames } from '../../Styling';
Copy link
Member

Choose a reason for hiding this comment

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

unneeded?

Copy link
Author

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'
Copy link
Member

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.

Copy link
Member

@dzearing dzearing left a 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
@@ -0,0 +1,325 @@
import * as React from 'react';
Copy link
Member

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.

Copy link
Author

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.",
Copy link
Member

Choose a reason for hiding this comment

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

typo

Copy link
Member

@dzearing dzearing left a comment

Choose a reason for hiding this comment

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

needs test.

@lambertwang-zz
Copy link
Author

@dzearing @cschleiden Can I get another review? I've made some changes and added enzyme tests for the component.

@lambertwang-zz lambertwang-zz dismissed cschleiden’s stale review April 18, 2018 21:15

Last response 82 days ago.

@lambertwang-zz lambertwang-zz requested a review from cliffkoh April 18, 2018 21:25
Copy link
Contributor

@cliffkoh cliffkoh left a 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.

@cliffkoh
Copy link
Contributor

@lambertwang FTFY: lambertwang-zz#1

…king

Fix build break issues with your PR
Copy link
Contributor

@cliffkoh cliffkoh left a 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.

@lambertwang-zz lambertwang-zz merged commit bd2e7b1 into microsoft:master Apr 19, 2018
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request Apr 20, 2018
* 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)
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TextField] It's would be nice if we support mask attribute for TextField

8 participants