Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onBlurResetsInput prop #591

Merged
merged 1 commit into from
Jan 13, 2016
Merged

Add onBlurResetsInput prop #591

merged 1 commit into from
Jan 13, 2016

Conversation

slybridges
Copy link
Contributor

Add an onBlurResetsInput prop that, if set to false, would keep user input in search box on onBlur.
Defaults to true.
Fixes #588

@slybridges
Copy link
Contributor Author

@JedWatson - anything you'd need from me to get this merged ?

@CodeWiesel
Copy link

I would love this feature as well

Anytime soon we can expect this?

@alurim
Copy link

alurim commented Jan 12, 2016

+1 this would be great to have

JedWatson added a commit that referenced this pull request Jan 13, 2016
@JedWatson JedWatson merged commit ec2c691 into JedWatson:master Jan 13, 2016
JedWatson added a commit that referenced this pull request Jan 13, 2016
@JedWatson
Copy link
Owner

Thanks for the bump - sorry I left it so long! and thanks for the PR @slybridges :)

@fhelwanger
Copy link
Contributor

Great!

Sorry to ask this... but do you know when this will be available on npm? We really need this feature to our app.

@JedWatson
Copy link
Owner

In about 15 minutes.

@fhelwanger
Copy link
Contributor

Thanks! I'll update our project.

We're using a custom build until now :)

@frodrigueza
Copy link

Is this available on npm? We need this feature a lot! Thanks!

@JedWatson
Copy link
Owner

@frodrigueza it's been available since version 1.0.0-beta9 :)

@frodrigueza
Copy link

Ok, thanks @JedWatson .

@tomascharad
@javiersubiabre

@samism
Copy link

samism commented Feb 6, 2020

Hello, I see

"onBlurResetsInput / onCloseResetsInput / onSelectResetsInput REMOVED now that inputValue can be controlled, these should be unnecessary"

Can someone provide an example of how to achieve the equivalent effect of onBlurResetsInput using inputValue? Thank you.

Edit: Found it: https://react-select.com/advanced#controlled-props

@gitowiec
Copy link

gitowiec commented Sep 2, 2020

I wonder why this works wrong. If I connect inputValue with my state (React.useState) React-Select should leave the input value without change if onBlur happens. One should be able to manage if he wants to clear unknown option of AsyncCreatable when blur happens. What do you think @JedWatson ?

@Shreyam-Saha
Copy link

@samism Hey what about if I am using a functional Component ? How can I write the onInputChange method ?

@ebonow
Copy link
Collaborator

ebonow commented Dec 10, 2020

Greetings
https://codesandbox.io/s/react-select-editable-and-selectable-6nfdv

@Shreyam-Saha
This example should show you how to use the onBlur functionality with a custom component. In this example, I'm using a custom Input to keep it rendered visibly instead of hiding it.

@gitowiec
If you want to leave the input then you can follow my code example and change this:

    // onBlur => setInputValue to last selected value
    if (action === "input-blur") {
      setInputValue(value ? value.label : "");
    }

    // onInputChange => update inputValue
    else if (action === "input-change") {
      setInputValue(inputValue);
    }

to this:

    // onBlur => keep input value
    if ((action === "input-blur") || (action === "input-change")) {
      setInputValue(inputValue);
    }```

@Shreyam-Saha
Copy link

@ebonow This does not solve the issue. The text typed in the field goes away once I click away, I want it to stay

@Methuselah96
Copy link
Collaborator

@Shreyam-Saha What issue are you trying to solve? This PR is about making the text go away when you click away, which is why that's the assumption of the issue you're trying to solve.

The CodeSandbox provided shows you how to write an onInputChange method using a functional Component as requested. If you don't want the text to go away, just remove these lines in the onInputChange method:

    // onBlur => setInputValue to last selected value
    if (action === "input-blur") {
      setInputValue(value ? value.label : "");
    }

Finally, it would be appreciated if you don't down-vote people who are trying to help you. While @ebonow might not have answered the question the way you wanted him to, he has taken the time (out of his free time) to try to help you out. If someone responds to you and they didn't answer your question, it's better to just clarify your question, thank them for you helping you, and not down-vote them.

@Shreyam-Saha
Copy link

@Methuselah96 really sorry if I sounded rude.
@ebonow Appreciate the help though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dont't clear Input on onBlur