Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React semantic UI: How to set focus for input field of dropdown element

Is it possible to initially set focus to an input field of an Dropdown element?

<Dropdown
  name={name}
  placeholder='Select type'
  search
  searchInput={{ type: 'text' }}
  selection
  onChange={this.handleChange}
  options={options}
/>

So the user should be able to start typing/searching without the need of clicking on the dropdown input field...

like image 899
user3142695 Avatar asked Oct 17 '22 05:10

user3142695


1 Answers

If I understand your question correctly, you want to give your Dropdown component focus when your content is loaded?

If that is indeed the case, then you want to make use of Refs. See the following for a detailed example: Refs and the DOM

In particular:

When to Use Refs

There are a few good use cases for refs:

  • Managing focus, text selection, or media playback.
  • Triggering imperative animations.
  • Integrating with third-party DOM libraries.
like image 178
Thomas Hennes Avatar answered Oct 23 '22 20:10

Thomas Hennes