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.

Cannot clear value manually (not truly controlled) when there is no match

See original GitHub issue

It seems that the component is not controlled when the search result is not a match of the options.

Example: https://plnkr.co/edit/b85HMDbt0jUZjkwCE7jG?p=preview

Using 1.0.0-rc.10.

I use the component to do a complex search from a number of filters (react-select being one of them). My external function is unable to clear the component by simply settings value={} to the empty string/undefined/null.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
agirtoncommented, Nov 29, 2017

Hi @zivester you are right it’s never cleared out due to inputValue is still controlled within the Select component. This will be a harder bug to fix because we own the state with inputValue.

In regards to the value always being an object, you can pass in a falsey value or an object. A falsey value tells us that the value should be cleared.

1reaction
agirtoncommented, Nov 29, 2017

Hi @zivester the example you gave us includes some incorrect code.

The onChange handler should not be

onChange(val) {
      console.log("onChange: " + val);
      const value = { label: val || '', value: val || '' };
      this.setState({ value });
  }

but

onChange(val) {
      console.log("onChange: " + val);
      this.setState({ value: val });
  }

The reason is because you are still passing in an object and we don’t do a diff to check if all of the values on the object are empty.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Material-ui autocomplete clear value - reactjs - Stack Overflow
When I encountered this, it was when options for the autocomplete changed, and wanted to clear the input value.
Read more >
MatchIt.pdf - R Project
Several matching methods require or can involve the distance between treated and control units. Options include the Mahalanobis distance, ...
Read more >
REMOVE - Cypher Manual - Neo4j
Instead, if no value exists, the property is just not there. So, REMOVE is used to remove a property value from a node...
Read more >
AbstractControl - Angular
A control is disabled when its status is DISABLED . Disabled controls are exempt from validation checks and are not included in the...
Read more >
nuget.config File Reference - Microsoft Learn
You may need to configure clear elements to ensure no user or machine specific ... Passwords are encrypted and cannot be added manually....
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