Repository navigation
MudTreeView: Fix multi-selection checkboxes for items without a value - #13951
Merged
danielchalmers merged 1 commit intoOct 7, 2026
Merged
danielchalmers merged 1 commit into
danielchalmers merged 1 commit into
Conversation
Selection is tracked by value, so an item without a value can never be selected, but the multi-selection checkboxes still counted such items. A parent with a child without a value, or a parent without a value of its own, showed as partially checked when everything selectable under it was selected, and clicking it again could not clear the selection. Leave items without a value out of the tri-state calculation and out of the check that decides whether a click selects or clears. A leaf without a value has nothing to select, so its checkbox is now read-only instead of moving through partially checked and checked on its own. Fixes MudBlazor#13233
danielchalmers
approved these changes
Oct 7, 2026
Member
|
Thanks! |
This was referenced Oct 30, 2026
This was referenced Nov 22, 2026
This was referenced Nov 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13233
In
SelectionMode.MultiSelection, items without aValuebroke the checkboxes:ItemTemplatedoesn't passValue) showed as partially checked after the first click and as checked after the second, while nothing was selected andSelectedValuesstayed empty.Cause:
Selection is tracked by value, so an item without a value can never be selected, but two places still counted such items:
MudTreeViewItem.ComputeCheckBoxStateTriStatecounted them as unselected, so their parent could never show as fully checked. A parent without a value also counted itself.MudTreeView.OnItemClickAsyncincluded them when deciding whether everything under the clicked item was already selected. They never are, so the click selected everything again instead of clearing it.A click on a leaf without a value changes nothing in the tree, so the item doesn't re-render. The tri-state
MudCheckBoxhas already moved to its next state by itself (unchecked → partially checked → checked), and re-rendering with the same value wouldn't reset it either, because the checkbox only takes a parameter value when it changes.Change:
AutoSelectParent, which already ignores children without a value.Items still need a
Value(orTextforstring) to be selectable. Trees where every item has one behave as before.Not changed: a parent whose sub-items have no values either is not made read-only. Its children are only known after it renders, so it would need extra state tracking for an edge case where nothing can be selected anyway.
No public API changes.
Before/After:
Three multi-selection trees: the snippet from the issue, a folder without a value, and a parent with a note row that has no value. Each checkbox is clicked twice.
Before:
treeview_novalue_before.mp4
After:
treeview_novalue_after.mp4
Testing:
Five tests (seven cases) were added to
TreeViewTests, using the new viewer componentTreeViewMultiSelectionNoValueTest:TreeViewWith_MultiSelection_LeafWithoutValue_ShouldNotBeCheckableTreeViewWith_MultiSelection_ParentWithoutValue_ShouldToggleAndReflectItsChildrenTreeViewWith_MultiSelection_ChildWithoutValue_ShouldNotBlockParentToggleTreeViewWith_MultiSelection_AutoSelectParent_ShouldCheckParentWithChildWithoutValueTreeViewWith_MultiSelection_InitialSelection_ShouldIgnoreItemsWithoutValueAll of them fail without the change, and each of the three code changes is needed for at least one of them to pass.
In the browser (Edge), on the snippet from the issue, mouse clicks and Space/Enter/Backspace no longer change the checkbox of a leaf without a value. Before, they moved it between partially checked and checked.
On the TreeView docs page (
MudBlazor.Docs.Server), clicking every checkbox in the multi-selection examples gives the same results before and after the change.A randomized check compared every rendered checkbox and
SelectedValuesagainst the expected result after each click. It covered 1,200 generated trees with 35% or 65% of the items without a value, with and withoutAutoSelectParent, and 18,000 clicks in total, and found no differences. On trees where every item has a value, the rendered states after 3,750 clicks were identical before and after the change.On top of the latest
dev, in Release:MudBlazor.UnitTests6151 passed (2 skipped),MudBlazor.UnitTests.Docs1420 passed,MudBlazor.UnitTests.Analyzers391 passed, anddotnet format --verify-no-changesis clean. The library builds for net8.0, net9.0 and net10.0 without warnings.AI assistance was used for the tests; all changes were reviewed and verified locally.
Checklist: