Skip to content

Commit 1140b5b

Browse files
committed
refactor: 更改参数名称为 AllowDrag
1 parent 5bce9a7 commit 1140b5b

File tree

4 files changed

+21
-41
lines changed

4 files changed

+21
-41
lines changed

src/BootstrapBlazor/Components/TreeView/TreeView.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ else
6868
RenderFragment RenderRow(TreeViewItem<TItem> item) =>
6969
@<TreeViewRow @key="item" IsActive="GetActive(item)" Index="GetIndex(item)" Item="item"
7070
NodeIcon="@NodeIcon" ExpandNodeIcon="@ExpandNodeIcon" LoadingIcon="@LoadingIcon"
71-
MaxSelectedCount="MaxSelectedCount" Draggable="ItemDraggable" PreviewDrop="_previewDrop"
71+
MaxSelectedCount="MaxSelectedCount" AllowDrag="AllowDrag" PreviewDrop="_previewDrop"
7272
ToolbarEditTitle="@ToolbarEditTitle" ToolbarEditLabelText="@ToolbarEditLabelText"
7373
IsDisabled="IsDisabled" CanExpandWhenDisabled="CanExpandWhenDisabled"
7474
ShowCheckbox="ShowCheckbox" ShowIcon="ShowIcon"

src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,19 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
269269
public bool AutoCheckParent { get; set; }
270270

271271
/// <summary>
272-
/// Gets or sets whether to enable item dragging. Default is false.
272+
/// Gets or sets a value indicating whether drag-and-drop operations are allowed. Default is false
273273
/// </summary>
274274
[Parameter]
275-
public bool ItemDraggable { get; set; }
275+
public bool AllowDrag { get; set; }
276276

277277
/// <summary>
278-
/// Gets or sets the callback method to be invoked when an item is dropped.
279-
/// Drop action can be cancelled by returning false.
278+
/// Gets or sets the asynchronous callback that is invoked when a drag-and-drop operation ends.
280279
/// </summary>
280+
/// <remarks>This callback allows handling of the finalization of a drag-and-drop operation, such as
281+
/// updating the data model or providing feedback to the user. If not set, no action is taken when the drag
282+
/// operation ends.</remarks>
281283
[Parameter]
282-
public Func<TreeDropEventArgs<TItem>, Task<bool>> OnDrop { get; set; } = _ => Task.FromResult(true);
284+
public Func<TreeDropEventArgs<TItem>, Task<bool>>? OnDragItemEndAsync { get; set; }
283285

284286
[Inject]
285287
[NotNull]

src/BootstrapBlazor/Components/TreeView/TreeViewRow.razor

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,6 @@
99
<div class="tree-content-body">
1010
<DynamicElement TagName="i" class="@CaretClassString" TriggerClick="CanTriggerClickNode" OnClick="ToggleNodeAsync"></DynamicElement>
1111
<i class="@NodeLoadingClassString"></i>
12-
13-
@if (Draggable && !_draggingItem)
14-
{
15-
<div class="tree-drop-zone">
16-
<div class="tree-drop-child-inside"
17-
ondragover="event.preventDefault();"
18-
@ondragenter="DragEnterChildInside"
19-
@ondragleave="DragLeaveChildInside"
20-
@ondrop="DropChildInside"></div>
21-
<div class="tree-drop-child-below"
22-
ondragover="event.preventDefault();"
23-
@ondragenter="DragEnterChildBelow"
24-
@ondragleave="DragLeaveChildBelow"
25-
@ondrop="DropChildBelow"></div>
26-
</div>
27-
}
28-
2912
@if (ShowCheckbox)
3013
{
3114
<Checkbox Value="@Item" IsDisabled="ItemDisabledState"
@@ -35,7 +18,7 @@
3518
</Checkbox>
3619
}
3720
<DynamicElement class="@NodeClassString" TriggerClick="!ItemDisabledState" OnClick="ClickRow"
38-
draggable="@(Draggable ? "true" : "false")"
21+
draggable="@DraggableString"
3922
@ondragstart="DragStart" @ondragend="DragEnd">
4023
@if (ShowIcon)
4124
{

src/BootstrapBlazor/Components/TreeView/TreeViewRow.razor.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ public partial class TreeViewRow<TItem>
139139
[Parameter]
140140
public Func<TItem, string?, Task<bool>>? OnUpdateCallbackAsync { get; set; }
141141

142+
/// <summary>
143+
/// Gets or sets whether the node can be dragged. Default is false.
144+
/// </summary>
145+
[Parameter]
146+
public bool AllowDrag { get; set; }
147+
142148
[Inject]
143149
[NotNull]
144150
private IOptionsMonitor<BootstrapBlazorOptions>? Options { get; set; }
@@ -176,11 +182,8 @@ public partial class TreeViewRow<TItem>
176182
.Build();
177183

178184
private bool IsPreventDefault => ContextMenuZone != null;
179-
180185
private bool _touchStart = false;
181-
182186
private bool _isBusy = false;
183-
184187
private bool _showToolbar = false;
185188

186189
/// <summary>
@@ -293,15 +296,6 @@ private async Task ClickRow()
293296
}
294297
}
295298

296-
#region Draggable
297-
298-
299-
/// <summary>
300-
/// Gets or sets whether the node can be dragged. Default is false.
301-
/// </summary>
302-
[Parameter]
303-
public bool Draggable { get; set; }
304-
305299
/// <summary>
306300
/// Gets or sets whether to preview the drop target when dragging. Default is false.
307301
/// </summary>
@@ -326,7 +320,8 @@ private async Task ClickRow()
326320
/// <summary>
327321
/// Triggered when an item is dropped
328322
/// </summary>
329-
[Parameter][Required]
323+
[Parameter]
324+
[Required]
330325
public Func<TreeDropEventArgs<TItem>, Task> OnItemDrop { get; set; } = null!;
331326

332327
private async Task DragStart(DragEventArgs e)
@@ -336,7 +331,8 @@ private async Task DragStart(DragEventArgs e)
336331
{
337332
_expandAfterDrop = true;
338333
await ToggleNodeAsync();
339-
}else
334+
}
335+
else
340336
{
341337
_expandAfterDrop = false;
342338
}
@@ -352,6 +348,8 @@ private void DragEnd(DragEventArgs e)
352348
OnItemDragEnd?.Invoke();
353349
}
354350

351+
private string? DraggableString => AllowDrag ? "true" : null;
352+
355353
private bool _previewChildLast;
356354
private bool _previewChildFirst;
357355
private bool _previewBelow;
@@ -424,7 +422,4 @@ private async Task DropChildBelow(DragEventArgs e)
424422
var dropTask = OnItemDrop.Invoke(args);
425423
await dropTask;
426424
}
427-
428-
429-
#endregion
430425
}

0 commit comments

Comments
 (0)