Typeahead icon indicating copy to clipboard operation
Typeahead copied to clipboard

[Bug] SelectedTemplate does not show when value set outside of the control

Open askolniak opened this issue 4 years ago • 5 comments

Describe the bug After update from 4.5.1 to 4.6.0 content of the control stopped to refresh when value is initially null and then is changed outside of the control. The IsShowingMask is initially set to false if the value is null during OnInitialized and it can be set to true only in the Initialize method. The Initialize in the previous version was called in OnParametersSet which now was removed and component stopped to respond to StateHasChanged invoked from parent.

To Reproduce

  1. Place two Typeahead controls operating on values of the same type (value1 and value2),
  2. In the ValueChanged event handler of the first control set: value1 = selectedValue; value2 = selectedValue;
  3. In version 4.5.1 when I select a value from the first Typeahead it is shown in both,
  4. In 4.6 the new value is not shown in the second Typeahead.

Expected behavior A component should be kept synchronized with the value.

Hosting Model (is this issue happening with a certain hosting model?):

  • Blazor WebAssembly

askolniak avatar May 28 '21 14:05 askolniak

@chrissainty no comment?

kamranghamsari avatar Jun 02 '21 06:06 kamranghamsari

@kamranghamsari This requires some investigation and I don't have any free time for this right now. Feel free to look into it and propose a solution.

chrissainty avatar Jun 02 '21 10:06 chrissainty

I had time to see the samples closely there was no sample with ValueChanged event handler but you should use bind-value instead of Value and not use the ValueChanged event handler I'm sorry it's not much I will find a proper solution @chrissainty @askolniak

kamranghamsari avatar Jun 12 '21 12:06 kamranghamsari

I have the same issue.

GioviQ avatar Jun 14 '21 13:06 GioviQ

Hey, I encountered the same issue. I bypassed it by doing the following:

  1. @bind-Value to a encapsulated object, with @ref to BlazoredTypeahead <BlazoredTypeahead @ref="TypeAhead" id="taskId" placeholder="Choose Task" MaximumSuggestions="50" SearchMethod="SearchWorkItems" @bind-Value="SelectedTask" EnableDropDown="true">

  2. Declared TypeAhead prop in the component private BlazoredTypeahead<BaseWorkItem, BaseWorkItem> TypeAhead { get; set; }

  3. On object update:

public BaseWorkItem SelectedTask
{
    get => _selectedTask;
    set
    {
        _selectedTask = value;
        if (TypeAhead is not null)
        {
            TypeAhead.Value = _selectedTask; 
            TypeAhead.ResetControlBlur().GetAwaiter();
            StateHasChanged();
        }

        TaskUpdated.InvokeAsync().GetAwaiter();
        StateHasChanged();
    }
}

antonio-mikulic avatar Jul 01 '21 09:07 antonio-mikulic