Skip to content

Commit 2f25bfa

Browse files
committed
fix: fix initializing label state when defaultValue is given
1 parent a069062 commit 2f25bfa

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/components/TextInput/TextInput.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,20 @@ class TextInput extends React.Component<TextInputProps, State> {
184184
}
185185

186186
state = {
187-
labeled: new Animated.Value(this.props.value ? 0 : 1),
187+
labeled: new Animated.Value(
188+
(this.props.value !== undefined
189+
? this.props.value
190+
: this.props.defaultValue)
191+
? 0
192+
: 1
193+
),
188194
error: new Animated.Value(this.props.error ? 1 : 0),
189195
focused: false,
190196
placeholder: '',
191-
value: this.props.value || this.props.defaultValue,
197+
value:
198+
this.props.value !== undefined
199+
? this.props.value
200+
: this.props.defaultValue,
192201
labelLayout: {
193202
measured: false,
194203
width: 0,
@@ -201,8 +210,7 @@ class TextInput extends React.Component<TextInputProps, State> {
201210
componentDidUpdate(prevProps: TextInputProps, prevState: State) {
202211
if (
203212
prevState.focused !== this.state.focused ||
204-
prevState.value !== this.state.value ||
205-
this.props.defaultValue
213+
prevState.value !== this.state.value
206214
) {
207215
// The label should be minimized if the text input is focused, or has text
208216
// In minimized mode, the label moves up and becomes small

0 commit comments

Comments
 (0)