Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input#getRef receives a undefined reference if Icon is used in a floatingLabel Item) #1780

Closed
benjaminbillet opened this issue Apr 14, 2018 · 10 comments

Comments

@benjaminbillet
Copy link

benjaminbillet commented Apr 14, 2018

Related issues: #591 #1514
React native 0.55.1, React 16.0.0-alpha.3, NativeBase 2.4.2

Hi,

I have an issue with Input, Item#floatingLabel and Input#getRef.

<Form>
  <Item floatingLabel>
    <Label>MyLabel</Label>
    <Input getRef={e => console.log(e)} />
    <Icon name="person" />
  </Item>
</Form>

With this simple code, getRef is triggered but e is undefined. Interestingly, if I remove the Icon component, it works fine.

I dug a little bit in the code of Item.js, and I think the problem is caused by the following code:

if (this.props.floatingLabel && icon.length) {
...
  newChildren.push(
     <Input // here, the ref attribute is not defined
          key="l2"
          {...inputProps}
...
} else if (this.props.floatingLabel) {
...
  newChildren.push(
     <Input
          ref={c => (this._inputRef = c)} // here, the ref attribute is defined
          value={this.state.text}
          key="l2"
          {...inputProps}
...
}

I added the missing ref={c => (this._inputRef = c)} in the first block and it solved the problem.

akhil-ga added a commit that referenced this issue Apr 16, 2018
Fix for issue #1780.
Fix based on issue-comment #1780 (comment)
@ZeroCool00
Copy link

ZeroCool00 commented Apr 20, 2018

@akhil-geekyants is it fixed at ? cause it happen with me today? do i have to update to 0.55.3 ?

@ZeroCool00
Copy link

ZeroCool00 commented Apr 20, 2018

@akhil-geekyants How do i make it work? i also update item.js file.. but no effect?

i m getting this error:
screenshot_20180420-165451

@akhil-ga
Copy link
Contributor

@ZeroCool00 can you post your code

@ZeroCool00
Copy link

ZeroCool00 commented Apr 20, 2018

@akhil-geekyants

<Form style={styles.inputContainer}>
            <Item
                floatingLabel
                success={this.state.inputEmailSuccess}
                error={this.state.inputEmailError}
                style={{ flexDirection: 'row-reverse' }}
            >

              <Label>Email</Label>
              <Input
                returnKeyType='next'
                onSubmitEditing={() => { this.password._root.focus(); }}
                onChangeText={(value) => this.setState({ email: value })}
                blurOnSubmit={false}
              />
              <Icon name={this.state.iconName} /> // If i remove, error gone
            </Item>

            <Item
              floatingLabel
              success={this.state.inputPasswordSuccess}
              error={this.state.inputPasswordError}
              style={{ flexDirection: 'row-reverse' }}
            >
              <Label>Password</Label>

              <Input
                getRef={(input) => { this.password = input; }}
                onChangeText={(value) => this.setState({ password: value })}
                secureTextEntry
              />
              <Icon name={this.state.iconName} />  // If i remove, error gone
            </Item>
          </Form>

here i also added this line in item.js
untitled

@akhil-ga
Copy link
Contributor

@ZeroCool00 checked this. Fix is working. Attaching a gif

If you are making changes directly in the node_modules/native-base (not recommended), change

"main": "dist/src/index.js",

to

"main": "src/index.js",

in the main node_modules/native-base/package.json

Gif

getref

@ZeroCool00
Copy link

ZeroCool00 commented Apr 20, 2018

@akhil-geekyants Its working now.. Thank you for all your support.. I love native-base

@ZeroCool00
Copy link

@akhil-geekyants Today i check node-module, every changes i made is all gone.. and all issue is still remain. floating label cut and getRef in keyboard..

How to solve this. do i need to wait until you update version? or there is a way?

@SupriyaKalghatgi
Copy link
Contributor

@ZeroCool00 You will get the update tomorrow

@ZeroCool00
Copy link

@SupriyaKalghatgi ok Thanks

@SupriyaKalghatgi
Copy link
Contributor

Fixed with 2.4.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants