majorimi / blazor-components

Components collection and extensions for Blazor applications.
MIT License
327 stars 59 forks source link

Typeahead: OnSelectedItemChanged gets triggered twice #104

Open AncientGrief opened 3 years ago

AncientGrief commented 3 years ago

OnSelectedItemChanged get's triggered twice when clicking an item with the mouse or using the Enter button:

    <TypeaheadInput id="in1" class="form-control bg-dark" placeholder="@("Add Item ...")"
                @ref="refAddItemInput"
                Data="DataProvider.Items"
                LabelPropertySelector="x => x.Name"
                @bind-Value="@AddItemInput"
                SelectOnBlur="false"
                OnInput="@(text => {SelectedItemToAdd = null; typeaheadInputValue = text;})"
                TItem="Item"
                OnSelectedItemChanged="OnAddItem">
        <ItemTemplate>
            <div>
                <label>@context.Name</label>
            </div>
        </ItemTemplate>
    </TypeaheadInput>
  ...
    private void OnAddItem(Item item)
    {
        Model.AddItemToActiveStash(item);
    }
majorimi commented 3 years ago

Hi @AncientGrief, sorry for the late answer I was sick.

Yes checked it and it looks there is a double event triggering for OnSelectedItemChanged. Will resolve this in next release. Thanks.