MudTreeView does not respect custom comparer for selection
#10.732 aberto em 27 de jan. de 2025
Métricas do repositório
- Stars
- (10.394 estrelas)
- Métricas de merge de PR
- (Mesclagem média 6d 6h) (108 fundiu PRs em 30d)
Description
Feature request type
Enhance component
Component name
MudTreeView
Is your feature request related to a problem?
Having subitems with same content with MultiSelection mode, selecting one of them selects/unselects the other. Assigning the reference comparer doesn't help. Debugging the source reveals, that assigned Comparer isn't assigned to _selection HashSet.
<MudTreeView T="string" SelectionMode="SelectionMode.MultiSelection" @bind-SelectedValues="selectedValues1">
<MudTreeViewItem Text="Getting Started">
<MudTreeViewItem Text="Installation" />
</MudTreeViewItem>
<MudTreeViewItem Value='"Components"'>
<MudTreeViewItem Text="Avatar" Value='"MudAvatar"' />
<MudTreeViewItem Text="Button" Value='"MudButton"' />
<MudTreeViewItem Text="Installation" />
</MudTreeViewItem>
</MudTreeView>
even if comparer change:
<MudText Typo="Typo.caption" Class="mt-2 mb-5">Select same item with ref equals</MudText>
<MudTreeView T="string" Comparer="StringRefComparer" SelectionMode="SelectionMode.MultiSelection" @bind-SelectedValues="selectedValues2">
<MudTreeViewItem Text="Getting Started">
<MudTreeViewItem Text="Installation" />
</MudTreeViewItem>
<MudTreeViewItem Value='"Components"'>
<MudTreeViewItem Text="Avatar" Value='"MudAvatar"' />
<MudTreeViewItem Text="Button" Value='"MudButton"' />
<MudTreeViewItem Text="Installation" />
</MudTreeViewItem>
</MudTreeView>
I see same behavior.
Another suggestion would be to introduce additional property AutoSelectChildren for the case, selectiong all children nodes is not desired if selecting parent.
Describe the solution you'd like
I did a small fix to update the Hashset's comparer. Not sure if the Item Click event right place for this action but now I'm able to select only those item that were clicked:
if (! _selection.Comparer.Equals(Comparer))
{
_selection = GetSelection(); //_selection.Any() ? new HashSet<T>(_selection, Comparer) : new HashSet<T>(Comparer);
}
I could provide the change using PR
Have you seen this feature anywhere else?
No response
Describe alternatives you've considered
No response
Pull Request
- I would like to do a Pull Request
Code of Conduct
- I agree to follow this project's Code of Conduct