react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Creatable does not invoke onInputChange prop

Open wmcmeans opened this issue 10 years ago • 5 comments

The Creatable class does not run onInputChange when designated as a prop.

wmcmeans avatar Nov 03 '16 14:11 wmcmeans

I noticed something similar with AsyncCreatable. Since onInputChange is called as a prop directly in it's source, you can't overwrite it when calling a parent Select. I also noticed that onInputChange isn't invoked when blurring a select with an input value, even when onBlurResetsInput is set to true. Seems like it should, because refocusing the input then gives you a menu with the last input you typed.

stinoga avatar Nov 03 '16 17:11 stinoga

I was trying to use this event to catch when a user pastes in a comma separated string of values. Pretty unfortunate that it doesn't work as documented...

TheTedAdams avatar Dec 23 '16 19:12 TheTedAdams

I am seeing this issue as well for the Creatable component. The bug lies on these lines in that component:

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

	if (onInputChange) {
		onInputChange(input);
	}

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

Even though onInputChange() is called, the value is not returned. When I just use the Select component I am able to apply a masking function, whereas when using the Creatable component, that masking function value is never returned from the Creatable onInputChange call to the Select component. The function passed in as a prop is called, but the value is never returned up the call stack.

The correct code would look like this:

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) {
		return onInputChange(input);
	}
}

cc: @JedWatson

mhubenthal avatar Feb 22 '17 20:02 mhubenthal

Do we have any update on this? Creatable is still unable to modify text with the onInputChange prop.

@mhubenthal Your suggested fix will not work. It must also set this.input to the return value of this.props.onInputChange() else the resulting label created will include the last typed character.

cscholze avatar Oct 10 '17 21:10 cscholze

I believe this can be closed now because #2057 has been merged, could everyone please confirm that it solves the problem correctly for their use-case? and continue discussion on #2056 if not.

Thanks!

JedWatson avatar Oct 18 '17 06:10 JedWatson