Skip to content

Commit 3c4a37a

Browse files
committed
Add expected behaviour for web browser
1 parent 9fad803 commit 3c4a37a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/components/TextInput/BaseTextInput.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ class BaseTextInput extends Component {
8080
return;
8181
}
8282

83-
if (this.props.autoGrow) {
83+
if (this.props.autoGrow && this.props.shouldWaitWidthCalculation) {
8484
if (inputValue !== this.state.hiddenInputValue) {
8585
this.setState({hiddenInputValue: inputValue, selection: this.props.selection});
8686
}
8787

88-
if (prevState.textInputWidth === this.state.textInputWidth && this.props.shouldWaitWidthCalculation) {
88+
if (prevState.textInputWidth === this.state.textInputWidth) {
8989
return;
9090
}
9191
}
@@ -159,7 +159,7 @@ class BaseTextInput extends Component {
159159
if (this.props.onInputChange) {
160160
this.props.onInputChange(value);
161161
}
162-
if (!this.props.autoGrow) {
162+
if (!this.props.autoGrow || !this.props.shouldWaitWidthCalculation) {
163163
this.setState({value});
164164
}
165165
Str.result(this.props.onChangeText, value);
@@ -234,6 +234,8 @@ class BaseTextInput extends Component {
234234
], (finalStyles, s) => ({...finalStyles, ...s}), {});
235235
const maxHeight = StyleSheet.flatten(this.props.containerStyles).maxHeight;
236236
const isMultiline = this.props.multiline || this.props.autoGrowHeight;
237+
const defaultInputValue = this.state.value || this.props.placeholder;
238+
const defaultHiddenInputValue = this.state.hiddenInputValue || this.props.placeholder;
237239

238240
return (
239241
<>
@@ -393,7 +395,7 @@ class BaseTextInput extends Component {
393395
style={[...this.props.inputStyle, this.props.autoGrowHeight ? {maxWidth: this.state.width} : {}, styles.hiddenElementOutsideOfWindow, styles.visibilityHidden]}
394396
onLayout={e => this.setState({textInputWidth: e.nativeEvent.layout.width + 2, textInputHeight: e.nativeEvent.layout.height})}
395397
>
396-
{this.props.autoGrowHeight ? this.state.value : this.state.hiddenInputValue || this.props.placeholder}
398+
{this.props.autoGrowHeight || !this.props.shouldWaitWidthCalculation ? defaultInputValue : defaultHiddenInputValue}
397399
</Text>
398400
)}
399401
</>

src/components/TextInput/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import _ from 'underscore';
33
import styles from '../../styles/styles';
44
import BaseTextInput from './BaseTextInput';
55
import * as baseTextInputPropTypes from './baseTextInputPropTypes';
6+
import * as BrowserUtils from '../../libs/Browser';
67

78
class TextInput extends React.Component {
89
componentDidMount() {
@@ -22,7 +23,7 @@ class TextInput extends React.Component {
2223
<BaseTextInput
2324
// eslint-disable-next-line react/jsx-props-no-spreading
2425
{...this.props}
25-
shouldWaitWidthCalculation
26+
shouldWaitWidthCalculation={BrowserUtils.isMobile()}
2627
innerRef={(el) => {
2728
this.textInput = el;
2829
if (!this.props.innerRef) {

0 commit comments

Comments
 (0)