Skip to content
Merged
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
85 changes: 46 additions & 39 deletions src/components/ExpensiTextInput/BaseExpensiTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from 'react-native';
import Str from 'expensify-common/lib/str';
import ExpensiTextInputLabel from './ExpensiTextInputLabel';
import Text from '../Text';
import {propTypes, defaultProps} from './propTypes';
import themeColors from '../../styles/themes/default';
import styles from '../../styles/styles';
Expand Down Expand Up @@ -112,6 +113,7 @@ class BaseExpensiTextInput extends Component {
label,
value,
placeholder,
errorText,
hasError,
containerStyles,
inputStyle,
Expand All @@ -123,46 +125,51 @@ class BaseExpensiTextInput extends Component {

const hasLabel = Boolean(label.length);
return (
<View style={[styles.componentHeightLarge, ...containerStyles]}>
<TouchableWithoutFeedback onPress={() => this.input.focus()} focusable={false}>
<View
style={[
styles.expensiTextInputContainer,
!hasLabel && styles.pv0,
this.state.isFocused && styles.borderColorFocus,
hasError && styles.borderColorDanger,
]}
>
{hasLabel ? (
<ExpensiTextInputLabel
label={label}
labelTranslateX={
ignoreLabelTranslateX
? new Animated.Value(0)
: this.state.labelTranslateX
}
labelTranslateY={this.state.labelTranslateY}
labelScale={this.state.labelScale}
<View>
<View style={[styles.componentHeightLarge, ...containerStyles]}>
<TouchableWithoutFeedback onPress={() => this.input.focus()} focusable={false}>
<View
style={[
styles.expensiTextInputContainer,
!hasLabel && styles.pv0,
this.state.isFocused && styles.borderColorFocus,
(hasError || errorText) && styles.borderColorDanger,
]}
>
{hasLabel ? (
<ExpensiTextInputLabel
label={label}
labelTranslateX={
ignoreLabelTranslateX
? new Animated.Value(0)
: this.state.labelTranslateX
}
labelTranslateY={this.state.labelTranslateY}
labelScale={this.state.labelScale}
/>
) : null}
<TextInput
ref={(ref) => {
if (typeof innerRef === 'function') { innerRef(ref); }
this.input = ref;
}}
// eslint-disable-next-line
{...inputProps}
value={value}
placeholder={(this.state.isFocused || !label) ? placeholder : null}
placeholderTextColor={themeColors.placeholderText}
underlineColorAndroid="transparent"
style={[...inputStyle, errorText ? styles.errorOutline : undefined]}
onFocus={this.onFocus}
onBlur={this.onBlur}
onChangeText={this.setValue}
/>
) : null}
<TextInput
ref={(ref) => {
if (typeof innerRef === 'function') { innerRef(ref); }
this.input = ref;
}}
// eslint-disable-next-line
{...inputProps}
value={value}
placeholder={(this.state.isFocused || !label) ? placeholder : null}
placeholderTextColor={themeColors.placeholderText}
underlineColorAndroid="transparent"
style={inputStyle}
onFocus={this.onFocus}
onBlur={this.onBlur}
onChangeText={this.setValue}
/>
</View>
</TouchableWithoutFeedback>
</View>
</TouchableWithoutFeedback>
</View>
{Boolean(errorText) && (
<Text style={[styles.formError, styles.mt1]}>{errorText}</Text>
)}
</View>
);
}
Comment thread
aldo-expensify marked this conversation as resolved.
Expand Down
4 changes: 4 additions & 0 deletions src/components/ExpensiTextInput/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const propTypes = {
/** Input value placeholder */
placeholder: PropTypes.string,

/** Error text to display */
errorText: PropTypes.string,

/** Should the input be styled for errors */
hasError: PropTypes.bool,

Expand All @@ -28,6 +31,7 @@ const propTypes = {

const defaultProps = {
label: '',
errorText: '',
placeholder: '',
error: false,
containerStyles: [],
Expand Down