NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

floatingLabel set default value?

Open fbacker opened this issue 9 years ago • 13 comments

react-native, react and native-base version

react: 15.4.2 react-native: 0.42.3 native-base: 2.1.0

Expected behaviour

When setting "value" on <Input the floating label show go to the up position.

Actual behaviour

The floating label is above the <Input text

Steps to reproduce

    <Item floatingLabel>
              <Label>Förnamn</Label>
              <Input keyboardType='default'
              returnKeyType='next'
              autoFocus={false}
              autoCorrect={false}
              multiline={false}
              onChange={(event) => {
                let text1 = event.nativeEvent.text;
                self.setState({textFirst:text1});
              }}
              value={this.state.textFirst} />
            </Item>

Screenshot of emulator/device

screen shot 2017-04-03 at 12 48 06

Is the bug present in both ios and android or in any one of them?

Only tested ios

Any other additional info which would help us debug the issue quicker.

Create a view with a floatingLabel and set a default value.

fbacker avatar Apr 03 '17 10:04 fbacker

I got problems

iambanh2 avatar Apr 12 '17 08:04 iambanh2

@iambanh2 @fbacker seems to work fine . issueitem

geekrishabh avatar Apr 14 '17 09:04 geekrishabh

@GeekRishabh if you add this to the Input

value={this.state.selected1}

now when running it should have moved 'Förnamn' up and written 'key1' in the input. This does not happen :(

fbacker avatar Apr 18 '17 19:04 fbacker

i have the same problem. pre-filled inputs with floatingLabel doesn't floatUp the label

cristian-milea avatar Apr 18 '17 21:04 cristian-milea

+1 I have the same problem

sarahmarciano avatar May 03 '17 14:05 sarahmarciano

same problem, too

redwind avatar May 15 '17 16:05 redwind

+1 fields falling with value populated when form renders

jlcrow avatar May 15 '17 17:05 jlcrow

I'm also using redux-form for managing state. A bit of a pain, looks like NB is managing the state of the label in the Item component and don't check in the constructor if there are values in the component. When you submit and come back to the view with errors or pre-populate the view with input text you lose the internal component state that's holding the text value. I just switched the type on the Item component from using a "floatingLabel" to a "stackedLabel", they look the same when there's text present in the Input.

A little hackish, but needed a fix: Add a constructor on your component so it's only run on component creation.

constructor(props) {
      super(props);
      const { input } = props;
      this.hasValue = false;
      if (input.value !== undefined && input.value.length > 0) {
        this.hasValue = true;
      }
  }

In your render use the hasValue variable to determine which label to render:

    render() {
          const { input, secureTextEntry, label, meta: { touched, error }, ...custom } = this.props;
          <Item
             error={hasError}
             stackedLabel={this.hasValue}
             floatingLabel={!this.hasValue}
            >
              <Label>{label}</Label>
                <Input {...input} {...custom} />
            </Item>
          }

        ...

jlcrow avatar May 16 '17 15:05 jlcrow

+1 have same problem too.

Gary-Li avatar May 25 '17 07:05 Gary-Li

#627

shivrajkumar avatar Jun 02 '17 06:06 shivrajkumar

Same problem here. Works fine on iOS emulator, but when I go to device, doesn't work. :(

ital0 avatar Nov 09 '17 13:11 ital0

I am having the same issue for the version 2.12.1

prionkor avatar Jun 17 '19 19:06 prionkor

I am having the same issue for the version 2.13.13

suhail135 avatar Oct 29 '20 17:10 suhail135