Open charlesninane94 opened 4 days ago
https://try.mudblazor.com/snippet/GucyFvGAgLDIOyAu fixed version
Thank you very much, @ScarletKuro. Could you briefly explain what is happening there and when to use await Task.Yield() with MudBlazor?
Thank you in advance for your help.
It's complicated to explain. We use Blazor lifecycle methods to register MudChip
s inside the MudChipSet
, because Blazor doesn't have a specialized API to track the list of components inside the MudChipSet
. Since you're dynamically changing the list of MudChip
s, I think what's happening is that OnInitialized
is not fired until your button action has executed. Even if you call StateHasChanged
before setting selectedValue
, this doesn't guarantee it. That's why, when you set the selection to test4
, the internal list of chips: https://github.com/MudBlazor/MudBlazor/blob/43fbb956b46650885a4b25230fece4a1c81ed253/src/MudBlazor/Components/ChipSet/MudChipSet.razor.cs#L45
May not have been updated yet. Visually, it's not shown because the binding occurred before the internal chip list had been updated. However, Task.Yield
queues the continuation on the current synchronization context (the Blazor UI thread), which gives control back to the UI thread to finish any pending tasks. Only after that will your code continue and set selectedValue = "test4"
.
Things to check
Bug type
Component
Component name
MudChipSet
What happened?
https://try.mudblazor.com/snippet/wEmIPbwUzDgsjgXT
Why is this code not working?
Expected behavior
When I click on the button I expect the test4 chip to be selected.
Reproduction link
https://try.mudblazor.com/snippet/wEmIPbwUzDgsjgXT
Reproduction steps
Relevant log output
No response
Version (bug)
7
Version (working)
No response
What browsers are you seeing the problem on?
Chrome
On which operating systems are you experiencing the issue?
Windows
Pull Request
Code of Conduct