feat(TreeView): support Darg and Drop function
Issues
#6216
New Feature
Add Draggable TreeView
Summary By Copilot
Regression?
- [ ] Yes
- [x] No
Risk
- [ ] High
- [ ] Medium
- [x] Low
Verification
- [x] Manual (required)
- [ ] Automated
Packaging changes reviewed?
- [ ] Yes
- [ ] No
- [x] N/A
☑️ Self Check before Merge
⚠️ Please check all items below before review. ⚠️
- [ ] Doc is updated/provided or not needed
- [ ] Demo is updated/provided or not needed
- [ ] Merge the latest code from the main branch
Summary by Sourcery
Implement drag-and-drop support for TreeView nodes with customizable drop behaviors and visual previews.
New Features:
- Add ItemDraggable, Draggable, and PreviewDrop parameters to enable node dragging and drop preview.
- Introduce OnItemDragStart, OnItemDragEnd, OnItemDrop callbacks and an OnDrop handler for drop event customization.
- Define TreeDropEventArgs class and TreeDropType enum to represent drop operations.
Enhancements:
- Add SCSS styling and CSS classes for drop zones and preview indicators on tree nodes.
Documentation:
- Update sample TreeViews component to demonstrate draggable TreeView usage and OnDrop event logging.
Thanks for your PR, @syminomega. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.
Reviewer's Guide
This PR adds full drag-and-drop reordering support to the TreeView component by introducing draggable parameters and callbacks, rendering drop zones with preview indicators, and updating the component logic to handle item reordering on drop.
Sequence Diagram for TreeView Item Drag-and-Drop
sequenceDiagram
actor User
participant SourceRow as TreeViewRow (Source)
participant TargetRow as TreeViewRow (Target)
participant TreeViewComp as TreeView
User->>SourceRow: Initiates drag (ondragstart)
SourceRow->>SourceRow: DragStart(eventArgs)
SourceRow->>TreeViewComp: OnItemDragStart(SourceItem)
TreeViewComp->>TreeViewComp: OnItemDragStart(item): sets _draggingItem, _previewDrop, StateHasChanged()
User->>TargetRow: Drags over drop zone (ondragenter)
TargetRow->>TargetRow: DragEnterChildInside() / DragEnterChildBelow()
TargetRow->>TargetRow: Sets preview flags (e.g., _previewChildLast), Renders drop preview
User->>TargetRow: Drops item (ondrop)
TargetRow->>TargetRow: DropChildInside() / DropChildBelow()
TargetRow->>TreeViewComp: OnItemDrop(TreeDropEventArgs)
TreeViewComp->>TreeViewComp: OnItemDrop(args): sets args.Source
TreeViewComp->>TreeViewComp: Invokes user OnDrop(args) callback
alt User OnDrop returns true
TreeViewComp->>TreeViewComp: Reorders items (updates TreeViewItem parents/collections)
TreeViewComp->>TreeViewComp: Resets _draggingItem, _previewDrop, StateHasChanged()
end
User->>SourceRow: Drag operation ends (ondragend)
SourceRow->>SourceRow: DragEnd(eventArgs)
SourceRow->>TreeViewComp: OnItemDragEnd()
TreeViewComp->>TreeViewComp: OnItemDragEnd(): resets _previewDrop, _draggingItem, StateHasChanged()
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Implement draggable behavior in TreeViewRow |
|
Components/TreeView/TreeViewRow.razor.csComponents/TreeView/TreeViewRow.razor |
| Add drop preview and styling |
|
Components/TreeView/TreeView.razor.scss |
| Extend TreeView component to handle drag-and-drop |
|
Components/TreeView/TreeView.razor.csComponents/TreeView/TreeView.razor |
| Define drop event arguments and types |
|
Components/TreeView/TreeView.razor.csEnums/TreeDropType.cs |
| Update demo to showcase draggable TreeView |
|
Server/Components/Samples/TreeViews.razorServer/Components/Samples/TreeViews.razor.cs |
Tips and commands
Interacting with Sourcery
-
Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
-
Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. -
Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. -
Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. -
Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. -
Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. -
Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 100.00%. Comparing base (
1ae8579) to head (0cd9ec8).
Additional details and impacted files
@@ Coverage Diff @@
## main #6121 +/- ##
===========================================
+ Coverage 99.98% 100.00% +0.01%
===========================================
Files 718 718
Lines 31686 31679 -7
Branches 4471 4472 +1
===========================================
- Hits 31681 31679 -2
+ Misses 4 0 -4
+ Partials 1 0 -1
| Flag | Coverage Δ | |
|---|---|---|
| BB | 100.00% <100.00%> (?) |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
DraggableTree examples WIP