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 AutoFocus not working #6733

Closed
MikeCodeur opened this issue Apr 28, 2017 · 5 comments
Closed

AutoComplete AutoFocus not working #6733

MikeCodeur opened this issue Apr 28, 2017 · 5 comments
Labels
component: autocomplete This is the name of the generic UI component, not the React module!

Comments

@MikeCodeur
Copy link

Hello

I try to use autoFocus on AutoComplete

like that

<AutoComplete {...this.props}
autoFocus={this.state.autoFocus}

Versions 17.0.1

Do you know if its possible or a bug ?

@anvk
Copy link

anvk commented Jul 2, 2017

You can use the following workaround:

Add ref for your autocomplete

<AutoComplete

    ref={(input) => {this.autoCompleteInput = input;}}
/>

Force focus somewhere in the code

this.autoCompleteInput.refs.searchTextField.input.focus();

@oliviertassinari
Copy link
Member

Closed by #4783

@wsfuller
Copy link

wsfuller commented Feb 3, 2018

Still unable to get this to work

...
componentDidMount() {
    this.autoCompleteInput.refs.searchTextField.input.focus();
  }
...
  <AutoComplete
          autoFocus
          ref={(input) => {this.autoCompleteInput = input;}}
          name="proxySearch"
          hintText="Search for User"
          dataSource={this.state.dataSource}
          onUpdateInput={this.handleUpdateInput}
          filter={AutoComplete.noFilter}
          maxSearchResults={15}
          onNewRequest={this.handleNewRequest}
          dataSourceConfig={dataSourceConfig}
          fullWidth
        />
...

@gazpachu
Copy link

gazpachu commented Jun 15, 2018

Any solution for this? @wsfuller @oliviertassinari @anvk @mika75

I didn't find a solution in #4783

@gazpachu
Copy link

I've fixed it by adding autoFocus to the TextField:

function renderInput(inputProps) {
  const { classes, ref, ...other } = inputProps;

  return (
    <TextField
      fullWidth
      autoFocus
      InputProps={{
        inputRef: ref,
        classes: {
          input: classes.input
        },
        ...other
      }}
    />
  );
}

@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