question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Programmatically focus a Select

See original GitHub issue

It is possible to focus Textfields, buttons with a ref. This isn’t working with select. I do not mean autoFocus. I want to focus on a select field when a user clicks on a button.

My code:

<FormControl className="select100"> <Select ref={(formControll) => { this.formControll = formControll; }} native value={aValue} input={<Input id="integer" />} > {possibleOptions.map((item, key) => { return (<option value={item} key={key}>{item}</option>) })} </Select> </FormControl>

If I now try to set the focus on the select with: this.formControll.focus(); it isn’t working.

Tech Version
Material-UI 1.0.0-beta.24
React 16.2.0
browser Chrome

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
joshwoodingcommented, Nov 11, 2018

@sedi0861 https://codesandbox.io/s/8nj6jz8n38 If I change handleFocus to use your textInput ref it works

2reactions
joshwoodingcommented, Nov 11, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Programmatically set focus on select · Issue #1212 - GitHub
Hello, How do I set the focus via JS on the bootstrap-select? I tried the focus() function on the select tag, and in...
Read more >
Set focus on specific select box - javascript - Stack Overflow
I have multiple select boxes in the pages. I want to set focus on first element of specific select box. Here it shows...
Read more >
HTMLElement.focus() - Web APIs | MDN
Select the button to set focus on the text field. Focus on a button. This example demonstrates how you can set the focus...
Read more >
Set focus to and select text in input field - OutSystems
Hi, I use the input_SetFocus widget to set the cursor in the SearchInput field together with an onfocus extended property to select the...
Read more >
Set Focus on <select> Element on Page Load - EncodeDna.com
This post has two examples showing how to set focus and automatically expand select dropdown option on page load using HTML5 attribute and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found