TagPicker: CreateGenericItem doesn't work correctly when itemLimit is set
Environmental Information
- ** Package version (s) **: 8.44.0
- ** Browser and OS Versions **: Chrome
Please provide a reproduction of the error in the code-behind:
https://codepen.io/vorobievik/pen/eYGrKwX?editors=1111
Actual Behavior:
if we set a custom tag with itemLimit and press Enter - the last item was added and then removed (I think the reason is in the bubbling event - because after addItem onRemoveItem is called)
Expected Behavior:
a custom tag can be added using itemLimit
Requested priority: (high)
Following this issue, exists in version 8.49.0
There is a race condition, if you add a debugger you will see that this works as expected.
BasePicker.prototype.canAddItems = function () {
var items = this.state.items;
var itemLimit = this.props.itemLimit;
return itemLimit === undefined || items.length < itemLimit;
};
This function is being called in multiple places in the base picker. The last condition determines whether the item should be added to the selected items list and this.props.itemLimit is not correct because of the race condition. The function call that is causing this has to be isolated.
The other function that maybe causing an issue is the following, it works with a debugger too :
_this._completeGenericSuggestion = function () {
if (_this.props.onValidateInput &&
_this.input.current &&
_this.props.onValidateInput(_this.input.current.value) !== ValidationState.invalid &&
_this.props.createGenericItem) {
var itemToConvert = _this.props.createGenericItem(_this.input.current.value, _this.props.onValidateInput(_this.input.current.value));
_this.suggestionStore.createGenericSuggestion(itemToConvert);
_this.completeSuggestion();
}
Thanks for filing this issue with us. To set expectations, the developers will review this issue once capacity allows.
@spmonahan - Would you be able to confirm if this is a regression, or if this behavior is an issue? Thanks
Because this issue has not had activity for over 180 days, we're automatically closing it for house-keeping purposes.
Still require assistance? Please, create a new issue with up-to date details.