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 selection using provided 'clear' Button

See original GitHub issue

‘react-select’: version “2.0.0”

JSX:

          <FormSelect
            isClearable={this.state.cohort_report_cohort !== null}
            isSearchable={false}
            onChange={option =>
              this.updateValue('cohort_report_cohort', option.value)
            }
            defaultValue={this.state.cohort_report_cohort}
            options={this.props.cohort_options}
            placeholder="Select Cohort..."
          />

Example:

clear-not-working

Any advice would be appreciated.

Issue Analytics

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

github_iconTop GitHub Comments

7reactions
noreekcommented, Jan 19, 2019

option variable is NULL in case of clearing (in provided example inside onChange). So passing option.value to updateValue method fails - check your console for error.

To fix it: this.updateValue('cohort_report_cohort', option ? option.value : null);

7reactions
cutterblcommented, Nov 1, 2018

One, shouldn’t your isClearable just be there? it won’t show the ‘x’ if there’s no value in the field. Second, what does your updateValue method look like? And onChange method signature also provides an action that you can key off of for specific types of changes.

onChange={(option, {action}) => this.doSomething(option, action)}

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to clear react-select values on button click without adding ...
How do I tell react-select to just clear the selected values and not add it in the options array anywhere ? import React,...
Read more >
Components - React Select
The indicators that react-select will check to render by are: Clear Indicator; Loading Indicator; Dropdown Indicator. See props docs for more details. Custom ......
Read more >
useSelect | Downshift
In the example below we open the menu when the toggle button is hovered, and clear the selection by clicking on the custom...
Read more >
Clear cells of contents or formats - Microsoft Support
Tip: To cancel a selection of cells, click any cell on the worksheet. On the Home tab, in the Editing group, click the...
Read more >
react-select - npm
A Select control built with and for ReactJS. Latest version: 5.7.0, last published: 24 days ago. Start using react-select in your project by...
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