diff --git a/src/components/TextInput/BaseTextInput.js b/src/components/TextInput/BaseTextInput.js index d399567248c4..330a39ed0587 100644 --- a/src/components/TextInput/BaseTextInput.js +++ b/src/components/TextInput/BaseTextInput.js @@ -10,10 +10,9 @@ import themeColors from '../../styles/themes/default'; import styles from '../../styles/styles'; import Icon from '../Icon'; import * as Expensicons from '../Icon/Expensicons'; -import InlineErrorText from '../InlineErrorText'; +import Text from '../Text'; import * as styleConst from './styleConst'; import TextInputWithName from '../TextInputWithName'; -import Text from '../Text'; import * as StyleUtils from '../../styles/StyleUtils'; class BaseTextInput extends Component { @@ -180,6 +179,9 @@ class BaseTextInput extends Component { // eslint-disable-next-line react/forbid-foreign-prop-types const inputProps = _.omit(this.props, _.keys(baseTextInputPropTypes.propTypes)); const hasLabel = Boolean(this.props.label.length); + const inputHelpText = this.props.errorText || this.props.hint; + const formHelpStyles = this.props.errorText ? styles.formError : styles.formHelp; + return ( <> @@ -232,6 +234,7 @@ class BaseTextInput extends Component { this.props.secureTextEntry && styles.pr2, ]} multiline={this.props.multiline} + maxLength={this.props.maxLength} onFocus={this.onFocus} onBlur={this.onBlur} onChangeText={this.setValue} @@ -256,10 +259,26 @@ class BaseTextInput extends Component { - {!_.isEmpty(this.props.errorText) && ( - - {this.props.errorText} - + {(!_.isEmpty(inputHelpText) || !_.isNull(this.props.maxLength)) && ( + + {!_.isEmpty(inputHelpText) && ( + {inputHelpText} + )} + {!_.isNull(this.props.maxLength) && ( + + {this.value.length} + / + {this.props.maxLength} + + )} + )} {/* diff --git a/src/components/TextInput/baseTextInputPropTypes.js b/src/components/TextInput/baseTextInputPropTypes.js index 3a0203561dcf..2f94e5668059 100644 --- a/src/components/TextInput/baseTextInputPropTypes.js +++ b/src/components/TextInput/baseTextInputPropTypes.js @@ -60,6 +60,12 @@ const propTypes = { /** Saves a draft of the input value when used in a form */ shouldSaveDraft: PropTypes.bool, + + /** Maximum characters allowed */ + maxLength: PropTypes.number, + + /** Hint text to display below the TextInput */ + hint: PropTypes.string, }; const defaultProps = { @@ -86,6 +92,8 @@ const defaultProps = { hideFocusedState: false, innerRef: () => {}, shouldSaveDraft: false, + maxLength: null, + hint: '', }; export {propTypes, defaultProps};