Fix: TreeItem Template click does not toggle Checkbox #2374
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.
Here is a professional PR description template formatted with Markdown, ready to be pasted into GitHub.
Fix: TreeItem Template click does not toggle Checkbox
Summary
This PR fixes an inconsistency in the
RadzenTreeItemcomponent where clicking the content of a customTemplatefails to toggle the associated checkbox, whereas clicking defaultTextworks as expected.The Issue
When
AllowCheckBoxes="true", the default rendering logic wraps the item text in a<label for="...">. This leverages native HTML behavior to toggle the checkbox when the text is clicked.However, when a
<Template>is provided, the content is wrapped in a standard<div>. As a result, clicking the template content triggers the Selection (highlight) event via event bubbling, but fails to trigger the Checked state change. This creates a confusing UX where the user expects the checkbox to toggle upon clicking the row, but it does not.The Fix
I have updated
RadzenTreeItem.razorandRadzenTreeItem.razor.csto programmatically handle the toggle logic when a Template is clicked.<div>(rather than changing it to a<label>) to ensure valid HTML semantics, as custom templates may contain interactive elements (buttons, inputs) which are illegal inside a label.OnTemplateClickmethod that checks ifAllowCheckBoxesis true and toggles theCheckedChangestate.@onclick="OnTemplateClick"to the template wrapperdiv.Technical Changes
RadzenTreeItem.razor.cs
Added handler logic:
RadzenTreeItem.razor
Updated markup to attach the handler:
Reproduction Steps
RadzenTreewithAllowCheckBoxes="true".<Template>forRadzenTreeLevel.Checklist