From 9f7388949ea5c0ed8ea1a84374216cbdebd5f591 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 14 Apr 2021 08:59:50 -1000 Subject: [PATCH] dont enforce default value for text input --- src/components/TextInputFocusable/index.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/components/TextInputFocusable/index.js b/src/components/TextInputFocusable/index.js index ba75dc946c52..01c038bdb8b5 100644 --- a/src/components/TextInputFocusable/index.js +++ b/src/components/TextInputFocusable/index.js @@ -47,8 +47,8 @@ const propTypes = { }; const defaultProps = { - defaultValue: '', - value: '', + defaultValue: undefined, + value: undefined, maxLines: -1, onPasteFile: () => {}, shouldClear: false, @@ -78,15 +78,15 @@ class TextInputFocusable extends React.Component { constructor(props) { super(props); + const initialValue = props.defaultValue + ? `${props.defaultValue}` + : `${props.value || ''}`; + this.state = { numberOfLines: 1, selection: { - start: this.props.defaultValue - ? `${this.props.defaultValue}`.length - : `${this.props.value}`.length, - end: this.props.defaultValue - ? `${this.props.defaultValue}`.length - : `${this.props.value}`.length, + start: initialValue.length, + end: initialValue.length, }, }; } @@ -220,9 +220,6 @@ class TextInputFocusable extends React.Component { const propStyles = StyleSheet.flatten(this.props.style); propStyles.outline = 'none'; const propsWithoutStyles = _.omit(this.props, 'style'); - const propsWithoutValueOrDefaultValue = this.props.defaultValue - ? _.omit(propsWithoutStyles, 'value') - : _.omit(propsWithoutStyles, 'defaultValue'); return ( this.textInput = el} @@ -233,7 +230,7 @@ class TextInputFocusable extends React.Component { numberOfLines={this.state.numberOfLines} style={propStyles} /* eslint-disable-next-line react/jsx-props-no-spreading */ - {...propsWithoutValueOrDefaultValue} + {...propsWithoutStyles} disabled={this.props.isDisabled} /> );