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

Creatable with onInputChange with no return gives promptTextCreator undefined #2514

Closed
mantissa7 opened this issue Apr 12, 2018 · 1 comment

Comments

@mantissa7
Copy link
Contributor

mantissa7 commented Apr 12, 2018

I've noticed what may be considered a bug in Creatable. It's not necessarily a bug as I suppose the code is doing what it should be, but the implementation is slightly confusing and caught me off guard.

When using Creatable with the onInputChange prop, if the prop func returns nothing, the the prompTextCreator doesn't "work". the code at line 119 in Creatable.js sets this.inputValue to the result of onInputChange. When nothing is returned, the value is set to undefined. When promptTextCreator tries to run, it sees only undefined and not what is currently written in the field.

I've created an example at StackBlitz.

my proposal is to change line 119 (v1.2.1):

onInputChange (input) {
	const { onInputChange } = this.props;

	// This value may be needed in between Select mounts (when this.select is null)
	this.inputValue = input;

	if (onInputChange) {
		this.inputValue = onInputChange(input) || this.inputValue; // fix is here
	}

	return this.inputValue;
}

I haven't tested this yet but I imagine this addresses the issue.

While this may not be a bug as such, it might be a nice quality-of-life thing, as it took me a while to find out why it suddenly wasn't working.

@flexdinesh
Copy link
Collaborator

Hey @mantissa7 v1 of react-select is no longer maintained. Chances are this issue might already be fixed or non-existent in v2.

I'm closing this issue/PR now. Feel free add your thoughts in #3981 and reference this issue/PR if needed.

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

No branches or pull requests

3 participants