Open MartinSoka opened 1 year ago
I was able to get it working when i use @bind-SelectedValues and no child component. However once i want to extract this into a separate component and use the @ref keyword together with the EventCallback, the items are not displayed as selected in the MudSelectExtended.
This is the edited code:
private async Task HandleSelectionChanged()
{
HashSet<Item> uniqueObjects = new HashSet<Item>(
SelectedItems .Concat(mudSelect.SelectedValues),
new TypeEqualityComparer());
await SelectedItemsChanged.InvokeAsync(uniqueObjects);
}
public class TypeEqualityComparer : IEqualityComparer<Item>
{
public bool Equals(Item x, Item y)
{
return x.Id == y.Id;
}
public int GetHashCode(Item obj)
{
return obj.Id.GetHashCode();
}
}
Hi community, I have a chipset in my parent component and a MudSelectExtended in child component. Both are updated properly, but when navigating away to a different page and navigating back to the page MudSelectExtended doesn't show the values as selected, it seems like it threats them as different objects. I was experimenting with SelectedValues prop, binding and ended up using the ref keyword with updating the values on eventcallback to parent.
I have read about overriding GetHashCode and Equals for custom reference types here: https://github.com/MudBlazor/MudBlazor/discussions/3532 however i wasn't able to get it working, so i was not sure if this is a good lead.
I have attached a simplified repo here: https://github.com/MartinSoka/MudBlazor_Repro/
I'm a blazor beginner so apologies in advance if i do something horribly wrong and many thanks for help!
parent
child-MySearchBox