fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

TagPicker: CreateGenericItem doesn't work correctly when itemLimit is set

Open vorobievik opened this issue 4 years ago • 4 comments

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)

vorobievik avatar Jan 04 '22 12:01 vorobievik

Following this issue, exists in version 8.49.0

Trish92 avatar Jan 05 '22 21:01 Trish92

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();
            }

Trish92 avatar Jan 07 '22 19:01 Trish92

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

gouttierre avatar Jan 18 '22 12:01 gouttierre

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.

msft-fluent-ui-bot avatar Jul 17 '22 13:07 msft-fluent-ui-bot