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.

How to clear select input programatically while on focus?

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

2reactions
viv3kkcommented, Apr 28, 2020

its not working for me. my value is changed to null, undefined or even blank, the select component still has previous value.

0reactions
ebonowcommented, Dec 4, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

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