Closed isaacalves closed 7 years ago
+1
Makes sense. I would be happy to accept a PR on this
Let me take a crack at fixing this.
@nkbt One thing though, why would you need to handle enter once timeout has passed. Rather it should be the Enter
can override the timeout?
Thanks @hozefaj! Timeout should be cancelled on Enter, that feels like the most logical way.
This is an issue with both notify on enter, and also notify on blur.
The problem is this line
this.notify
is a method, but the code is attempting to access a property this.notify.cancel
as if this.notify
were an object
That is ok, since lodash.debounce has .cancel method available ondebounced functions
In that case, the problem is this.notify
is not itself a debounced function. The debounced function is called from within this.notify
const debouncedChangeFunc = debounce(event => {
this.isDebouncing = false;
this.doNotify(event);
}, debounceTimeout);
this.notify = event => {
this.isDebouncing = true;
debouncedChangeFunc(event);
};
}
I've now fixed this bug, with code submitted as part of this PR
Should be fixed in react-debounce-input@3.0.1
I'm using something like this:
handleInputChange(e) { this.props.onInputChange(e.target.value); }
and on my render method:
<DebounceInput type='text' onChange={ this.handleInputChange.bind(this) } debounceTimeout={ 1000 } />
I see that
handleInputChange
is also called when I press Enter from the input field (although I could handle that myself in anonSubmit
handler on the form). I assume that's intended, but why then doeshandleInputChange
fires again after the timeout?Scenario:
I see that I can use
forceNotifyByEnter
so it's not called on Enter key press. That solves the problem, but actually it would be nice to have it being called on Enter key press as well, as long as it clears the timeout.