Dropdown children reinitialized (unmounted and remounted) every time an item is selected #364

Closed
opened 2026-01-29 17:36:06 +00:00 by claunia · 0 comments
Owner

Originally created by @PeteJobi on GitHub (Apr 8, 2022).

Is your feature request related to a problem? Please describe.
The RadzenDropDown and RadzenListBox component unmounts and remounts all its children everytime one of them is selected. This is fine when you're not using a Template. But if you are using one, and the Template contains complex components that manage their own state, then this becomes a problem.

Reproduction:
Download the repo locally, go to the https://blazor.radzen.com/listbox page. For the one that shows the Template example, replace the following:

//Replace this
<Template>
        Company: @((context as Customer).CompanyName)
</Template>

//With this
<Template>
       <Radzen.Blazor.RadzenTextBox Value="@((context as Customer).CompanyName)"></Radzen.Blazor.RadzenTextBox>
</Template>

Go to the RadzenTextBox component, add the below and put a breakpoint in it.

protected override void OnInitialized()
{
     base.OnInitialized();
}

Now run it. Everytime you select an item in the ListBox, the breakpoint gets hit for each item in the ListBox.

Describe the solution you'd like
I'd like the children items in both components to never unmount while the underlying data remains the same.

Describe alternatives you've considered
I have investigated, and the cause of this is the Key set on the children. The key is the underlying data itself, and if the reference changes, the component gets reinitialized. I'm going to make a pull request soon.

Originally created by @PeteJobi on GitHub (Apr 8, 2022). **Is your feature request related to a problem? Please describe.** The RadzenDropDown and RadzenListBox component unmounts and remounts all its children everytime one of them is selected. This is fine when you're not using a Template. But if you are using one, and the Template contains complex components that manage their own state, then this becomes a problem. **Reproduction**: Download the repo locally, go to the https://blazor.radzen.com/listbox page. For the one that shows the Template example, replace the following: ``` //Replace this <Template> Company: @((context as Customer).CompanyName) </Template> //With this <Template> <Radzen.Blazor.RadzenTextBox Value="@((context as Customer).CompanyName)"></Radzen.Blazor.RadzenTextBox> </Template> ``` Go to the RadzenTextBox component, add the below and put a breakpoint in it. ``` protected override void OnInitialized() { base.OnInitialized(); } ``` Now run it. Everytime you select an item in the ListBox, the breakpoint gets hit for each item in the ListBox. **Describe the solution you'd like** I'd like the children items in both components to never unmount while the underlying data remains the same. **Describe alternatives you've considered** I have investigated, and the cause of this is the Key set on the children. The key is the underlying data itself, and if the reference changes, the component gets reinitialized. I'm going to make a pull request soon.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#364