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

Expose some 'react-text-mask' props on the MaskedTextField component #408

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/components/Forms/MaskedTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export const maskedTextFieldPropTypes = {
floatingLabelText: PropTypes.string,
/** Sets width to 100% */
fullWidth: PropTypes.bool,
/**
* Tells the input whether to be in guide mode or not.
* https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#guide
*/
guide: PropTypes.bool,
/** Sets width to 162px */
halfWidth: PropTypes.bool,
/** FormComponent error for validation */
Expand All @@ -132,6 +137,13 @@ export const maskedTextFieldPropTypes = {
inputStyle: PropTypes.object,
/** Set by FormComponent by default. */
isValid: PropTypes.bool,
/**
* Changes the behavour of the input mask.
* When `true`, adding or deleting characters will not affect the positions of existing characters.
* When `false`, adding characters causes existing characters to advance.
* https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#keepcharpositions
*/
keepCharPositions: PropTypes.bool,
/** onFocus callback */
onFocus: PropTypes.func,
/** onChange callback
Expand Down Expand Up @@ -170,6 +182,8 @@ class MaskedTextField extends React.Component {
autoComplete: 'on',
disabled: false,
defaultValue: null,
guide: false,
keepCharPositions: true,
onChange: NoOp,
onKeyDown: NoOp,
onFocus: NoOp,
Expand Down Expand Up @@ -237,10 +251,12 @@ class MaskedTextField extends React.Component {
defaultValue,
disabled,
fullWidth,
guide,
halfWidth,
hasError,
id: inputId,
isValid,
keepCharPositions,
name,
required,
serverError,
Expand Down Expand Up @@ -288,7 +304,7 @@ class MaskedTextField extends React.Component {
mask={mask}
pipe={pipe}
id={inputId}
guide={false}
guide={guide}
name={name}
aria-required={required}
aria-invalid={hasError}
Expand All @@ -301,7 +317,7 @@ class MaskedTextField extends React.Component {
placeholder=""
defaultValue={value !== undefined ? undefined : defaultValue}
disabled={disabled}
keepCharPositions
keepCharPositions={keepCharPositions}
type={this.props.type}
render={(ref, props) => (
<input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ exports[`renders correctly 1`] = `
disabled={false}
floatingLabelText="Date of Birth"
getValue={[Function]}
guide={false}
hasError={false}
hintText="MM/DD/YYYY"
id="test_id"
isValid={true}
keepCharPositions={true}
mask={
Array [
/\\\\d/,
Expand Down Expand Up @@ -504,10 +506,12 @@ exports[`renders correctly with focus state 1`] = `
disabled={false}
floatingLabelText="Date of Birth"
getValue={[Function]}
guide={false}
hasError={false}
hintText="MM/DD/YYYY"
id="test_id"
isValid={true}
keepCharPositions={true}
mask={
Array [
/\\\\d/,
Expand Down Expand Up @@ -948,10 +952,12 @@ exports[`uses a custom theme for all child components if one is provided 1`] = `
disabled={false}
floatingLabelText="Date of Birth"
getValue={[Function]}
guide={false}
hasError={false}
hintText="MM/DD/YYYY"
id="test_id"
isValid={true}
keepCharPositions={true}
mask={
Array [
/\\\\d/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ exports[`renders correctly 1`] = `
disabled={false}
floatingLabelText="SSN"
getValue={[Function]}
guide={false}
hasError={false}
id="test_id"
isValid={true}
keepCharPositions={true}
mask={
Array [
/\\\\d/,
Expand Down Expand Up @@ -475,9 +477,11 @@ exports[`renders correctly with focus state 1`] = `
disabled={false}
floatingLabelText="SSN"
getValue={[Function]}
guide={false}
hasError={false}
id="test_id"
isValid={true}
keepCharPositions={true}
mask={
Array [
/\\\\d/,
Expand Down Expand Up @@ -888,9 +892,11 @@ exports[`uses a custom theme for all child components if one is provided 1`] = `
disabled={false}
floatingLabelText="SSN"
getValue={[Function]}
guide={false}
hasError={false}
id="test_id"
isValid={true}
keepCharPositions={true}
mask={
Array [
/\\\\d/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ exports[`renders correctly 1`] = `
disabled={false}
floatingLabelText="Phone Number"
getValue={[Function]}
guide={false}
hasError={false}
hintText="(555) 555-555"
id="test_id"
isValid={true}
keepCharPositions={true}
mask={
Array [
"(",
Expand Down Expand Up @@ -528,10 +530,12 @@ exports[`renders correctly with focus state 1`] = `
disabled={false}
floatingLabelText="Phone Number"
getValue={[Function]}
guide={false}
hasError={false}
hintText="(555) 555-555"
id="test_id"
isValid={true}
keepCharPositions={true}
mask={
Array [
"(",
Expand Down Expand Up @@ -987,10 +991,12 @@ exports[`uses a custom theme for all child components if one is provided 1`] = `
disabled={false}
floatingLabelText="Phone Number"
getValue={[Function]}
guide={false}
hasError={false}
hintText="(555) 555-555"
id="test_id"
isValid={true}
keepCharPositions={true}
mask={
Array [
"(",
Expand Down