SamProf / MatBlazor

Material Design components for Blazor and Razor Components
http://www.matblazor.com
MIT License
2.84k stars 384 forks source link

Why does MatTabGroup reinitializes tab child content when changing tabs? #773

Open groogiam opened 4 years ago

groogiam commented 4 years ago

Describe the question It seems that the MatTabGroup reinitializes its child controls each time a tab is switched. This means that the state of the control in the tab is completely wiped out. Is this by design? This essentially means that the control cannot be used for anything more than static content. E.g. if a tab group has two tabs with subcomponents that have forms switching essentially wipes out any in progress changes.

Blazorfiddle link The code below demonstrates this. The component is the standard component that is in the blazor template. In this example increment the counter, switch tabs and then switch back. You will see that the original counter is now reset to 0.

<MatTabGroup>
    <MatTab Label="1">
        <Counter></Counter>
    </MatTab>
    <MatTab Label="2">
        <Counter></Counter>
    </MatTab>
</MatTabGroup>

Expected behavior The state for tab child content should be maintained when switching tabs

Screenshots If applicable, add screenshots or .GIF captures to help explain your question. image

Additional context Add any other context about the question here.

PeteJobi commented 4 years ago

Same. My work around is keeping states outside the <MatTabGroup>. It will be nice to not lose state when switching tabs but I don't see a way to do that without having to just hide <MatTab> content.

groogiam commented 4 years ago

Seems like it might be a good feature to have a parameter to control how this renders.