How to clear select input programatically while on focus?
See original GitHub issueI am trying to add new options as user types and each option is added when the user types a comma. I’m trying to clear the select input field but no matter what I try, it just won’t. I have to click the field again before it disappears. I’ve tried the ff:
stateManager.setState({inputValue: ''})
- manually changing the value of
inputRef
to empty string - calling force update on
stateManager.select
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9
Top Results From Across the Web
ReactJS - Clear select value on focus - Stack Overflow
I need to clear the selected value of select dropdown as soon as user focus on the select element. I have used the...
Read more >HTML | Clearing the input field - GeeksforGeeks
Method 1: Clearing Input on Focus. Syntax: <input onfocus=this.value=''>. Approach: Create an input field. Set the onfocus attribute to NULL ...
Read more >focus-within - CSS: Cascading Style Sheets - MDN Web Docs
This selector is useful, to take a common example, for highlighting an entire <form> container when the user focuses on one of its...
Read more >HTML DOM Element focus() Method - W3Schools
The focus() method gives focus to an element (if it can be focused). See Also: The blur() Method (to remove focus). The onfocus...
Read more >Angular ng-select - GitHub
(close), Fired on select dropdown close ; (clear), Fired on clear icon click ; (focus), Fired on select focus ; (search), Fired while...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
its not working for me. my value is changed to null, undefined or even blank, the select component still has previous value.
Greetings everyone,
The text input can be cleared by making this a controlled input and passing an empty string to the
inputValue
Here is a codesandbox demonstrating this with the specification of a comma triggering the addition of a new option value.
There are likely other optimizations that could be made, but this should be sufficient to show the use-case is possible and how to proceed.
I will be closing this issue, but can reopen if there are related issues or concerns.