VDT.Core.Blazor.DragAndDropList
0.3.0
See the version list below for details.
dotnet add package VDT.Core.Blazor.DragAndDropList --version 0.3.0
NuGet\Install-Package VDT.Core.Blazor.DragAndDropList -Version 0.3.0
<PackageReference Include="VDT.Core.Blazor.DragAndDropList" Version="0.3.0" />
paket add VDT.Core.Blazor.DragAndDropList --version 0.3.0
#r "nuget: VDT.Core.Blazor.DragAndDropList, 0.3.0"
// Install VDT.Core.Blazor.DragAndDropList as a Cake Addin #addin nuget:?package=VDT.Core.Blazor.DragAndDropList&version=0.3.0 // Install VDT.Core.Blazor.DragAndDropList as a Cake Tool #tool nuget:?package=VDT.Core.Blazor.DragAndDropList&version=0.3.0
VDT.Core.Blazor.DragAndDropList
Blazor component that allows users to reorder items in a list by dragging and dropping.
Features
- Drag and drop items in a list to change the order
- Touch and mouse support
- Fully customizable item layout template
Usage
To start using this component, follow the below steps.
- Assign your list of items to the
Items
property - Inside the item template, there needs to be an element that has an
@onmousedown
and@ontouchstart
event callback tocontext.StartDragging
, passing theMouseEventArgs
andTouchEventArgs
, to start the dragging action - When the dragging item is dropped, the component
OnDropItem
event is triggered which provides an object of typeDropItemEventArgs<TItem>
; subscribe to this event to handle the reordering of your list
Please note that reordering must be done in client code since the component should not change its input property Items
. To handle reordering you can either
perform manual switching using the OriginalItemIndex
and NewItemIndex
properties of the event arguments parameter, or use the IList<T>.Reorder
with the
event arguments.
Example
<DragAndDropList Items="Items" OnDropItem="ItemDropped">
<ItemTemplate>
<div class="mt-3 p-3 bg-light border rounded d-flex justify-content-between align-items-center">
<div class="overflow-hidden">
<h5 class="text-truncate">@context.Item.Text</h5>
<div class="text-muted text-truncate">@context.Item.Id</div>
</div>
<button class="btn btn-primary" @onmousedown="context.StartDragging" @ontouchstart="context.StartDragging">
<span>↕</span><span class="ps-2 d-none d-lg-inline">Move</span>
</button>
</div>
</ItemTemplate>
</DragAndDropList>
@code {
private record Item(Guid Id, string Text);
private List<Item> Items { get; set; } = Enumerable.Range(1, 8).Select(i => new Item(Guid.NewGuid(), $"Item {i}")).ToList();
private void ItemDropped(DropItemEventArgs args) {
Items.Reorder(args);
}
}
Style
The only styles that get automatically applied to the list and its items are those that are needed to render the dragging and switching effects for the list items. Further styles can be applied either directly on the item layout template, or using below CSS classes.
drag-and-drop-list
for the list containerdrag-and-drop-list-item
for each list itemdrag-and-drop-list-item-active
for the list item that is currently being dragged
Example
/* Display a shadow around the currently active element's content */
.drag-and-drop-list-item-active > div {
box-shadow: 0 0 0.75rem #dee2e6;
}
/* Create smooth switching animations */
.drag-and-drop-list-item:not(.drag-and-drop-list-item-active) {
position: relative;
top: 0;
transition: top 0.4s ease-in-out;
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.0)
- VDT.Core.Blazor.GlobalEventHandler (>= 3.2.0)
-
net7.0
- Microsoft.AspNetCore.Components.Web (>= 7.0.0)
- VDT.Core.Blazor.GlobalEventHandler (>= 3.2.0)
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.0)
- VDT.Core.Blazor.GlobalEventHandler (>= 3.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Switch from DropItemEventArgs.ReorderedItems property to IList<T>.Reorder extension method for reordering list
- Remove generic type argument from DropItemEventArgs
- Switch to IList<T> interface for Items property
- Mark required component properties as required