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

Adds "onBlur" hook in TextInputComp onBlur prop #506

Merged
merged 2 commits into from
Jul 9, 2020

Conversation

sethcwhiting
Copy link
Contributor

Added this hook so that consumers of this package can include "onBlur" in their textInputProps just like they would with "onFocus".

@druvisc
Copy link

druvisc commented May 12, 2020

Relevant

@bell-steven
Copy link
Collaborator

bell-steven commented May 15, 2020

I can use onBlur in textInputProps. Am I missing something here?

    <GooglePlacesAutocomplete
        query={{
          key: GOOGLE_PLACES_API_KEY,
          language: 'en', // language of the results
        }}
        onPress={(data, details = null) => console.log(data)}
        textInputProps={{
          onBlur: () => console.log('hello'),
        }}
   />

@sethcwhiting
Copy link
Contributor Author

sethcwhiting commented May 15, 2020

@bell-steven Oh I see. I didn't realize that. As a user of the package, I'd rather use it like I use the onFocus prop, but you could leave it as is if you want, since it does the same thing. I'd just say it might be nice to at least mention that somewhere in the documentation. If you do end up wanting to merge this, I just fixed the conflict. Thanks!

@bell-steven
Copy link
Collaborator

How do you use the onFocus prop? In textInputProps or directly?

Very little of this library is well documented. It is an ongoing effort. PRs always welcome.

I really appreciate your taking the time to resolve the conflicts.

As an aside, as I wrote in the roadmap issue (#552) I would ideally like to see the number of props directly available from the library be drastically reduced. There are currently at least 46 props available. As an example, some of the TextInput props are exposed directly, while other need to be placed in textInputProps. We could either allow them all to be set directly on <GooglePlacesAutocomplete /> or move them all to TextInputProps.

@sethcwhiting
Copy link
Contributor Author

sethcwhiting commented May 15, 2020

Hey sorry, I just looked at my code again and I am using it the way you suggested:
textInputProps={{ onFocus: () => this.handleOnFocus(), onBlur: () => this.handleOnBlur() }}
The problem with it is that onBlur didn't allow you to hook into it like onFocus did. Instead, you could either leave it or overwrite it completely and lose the default blur behavior of the package. My change here allows you to keep the default behavior and add your own on top of it.

@bell-steven
Copy link
Collaborator

Thats why I am a little back and forth on whether I should merge this. On the one hand, there should be consistency between onFocus and onBlur. On the other hand, if you are overwriting the default onBlur function, not sure that hooking into the current onBlur function is something that is expected.

To solve you problem, would using a ref to call blur() in your handleOnBlur() solve your issue?

The question for me is, does blur() get called automatically? Or does it have to be called in onBlur? I have to dig into this when I have some time.

If you don't mind, I would like to leave this open for now.

@sethcwhiting
Copy link
Contributor Author

sethcwhiting commented May 15, 2020

This is the current default behavior:

  _onBlur = () => {
    this.triggerBlur();

    this.setState({
      listViewDisplayed: false
    });
  }

If you leave it so that passing the onBlur prop overwrites the default behavior, this.state.listViewDisplayed will remain true. If you don't want that to happen (like I don't), I don't know how you would prevent that the way the package is currently written.

@bell-steven
Copy link
Collaborator

You can use the listViewDisplayed prop for that :). (There may be a bug in this, see #398).

@sethcwhiting
Copy link
Contributor Author

Interesting. I may have to play around with that and see if I can get it to work for me 👍 Thanks for your work on this project, btw! Glad you picked it up.

@bell-steven
Copy link
Collaborator

Thanks. Holler if you get stuck. I'll be happy to try and help.

@bell-steven bell-steven changed the base branch from master to v1.8 July 9, 2020 21:25
@bell-steven bell-steven merged commit 9b9f573 into FaridSafi:v1.8 Jul 9, 2020
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

Successfully merging this pull request may close these issues.

3 participants