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

[AutoComplete] Ability to Set Props on the Input Field #4353

Closed
joncursi opened this issue May 26, 2016 · 7 comments
Closed

[AutoComplete] Ability to Set Props on the Input Field #4353

joncursi opened this issue May 26, 2016 · 7 comments
Labels
component: autocomplete This is the name of the generic UI component, not the React module!

Comments

@joncursi
Copy link

Problem description

The AutoComplete component does not expose an API / prop for setting a ref, class, id, or other unique identifier on the input element within it. This prevents the ability to call focus() programmatically on that input element from an action elsewhere in the app.

An example would be clicking a "search" button that then launches an AutoComplete component with focus programmatically placed on the input:

screen shot 2016-05-26 at 4 10 15 am

This would allow the user to only have to click once to start searching, rather than twice (the second time having to be on the input element itself).

Are there any workarounds for this?

@muibot muibot added the Triage label May 26, 2016
@joncursi
Copy link
Author

joncursi commented May 26, 2016

Here's one possible workaround I guess:

<AutoComplete
  ...
  className="search-bar__auto-complete"
  searchText={this.state.searchString}
  ...
/>
    setTimeout(() => {
      document.querySelector('.search-bar__auto-complete input').focus();
    }, 100);

It seems that a setTimeout is needed when searchText is being fed a value from state, as it takes a split second to compute and render.

@joncursi joncursi changed the title [AutoComplete] Programmatic Focus of the Input Field [AutoComplete] Ability to Set Props on the Input Field May 27, 2016
@joncursi
Copy link
Author

Another issue I'm running into is since we cannot set props on input, I cannot set type="search" to enable a custom keyboard such as:

esbmh

@LeeKevin
Copy link

Focus can be done on the AutoComplete field by using the focus() method.

componentDidUpdate() {
    this.refs.autocomplete.focus()
}
render () {
    return <AutoComplete ref="autocomplete" dataSource=... />
}

@LeeKevin
Copy link

This issue is related to #4556

@joncursi
Copy link
Author

@LeeKevin neat. But what if you need to focus the AutoComplete input from a different component (do not have access to this.refs)?

@LeeKevin
Copy link

LeeKevin commented Jun 27, 2016

If you set a refs name for the parent component, you can access it with this.refs.autocompleteParent.refs.autocomplete.focus(). You have access to all the same class properties and methods. Alternatively, you can check a set property flag in order to manually focus as in my previous comment. If you post your code, I can help you find cleaner solution to focus on render/update instead of using a timeout.

@oliviertassinari
Copy link
Member

Closed by #4783

@oliviertassinari oliviertassinari added the component: autocomplete This is the name of the generic UI component, not the React module! label Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

5 participants