Skip to content
# Sortable **Also known as:** SortableList, ReorderableList, DragAndDropList ## Description BitSortable is a drag-and-drop sortable list, inspired by SortableJS: reorder the items of a list, or drag them between lists that share a Group - with live reordering, slide animations, clone and move pull modes, swap thresholds, drag handles, filters, nested lists, swap mode, multi-drag and the keyboard, every step announced to screen readers. ## Parameters | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Animation | `int` | 150 | The duration in milliseconds of the slide animation of the items moving to their new positions, mirroring the SortableJS animation option. It follows the reduced-motion preference the way every animation of the library does (see ForceAnimation). Set to 0 to turn the animations off. | | CanDrop | `Func<BitSortableEventArgs<TItem>, bool>?` | null | Decides whether the dragged item may be placed at a position in this list, as the item reaches it: return false to refuse. Asked with the proposed move - NewIndex is the index the item would have here, FromId the list it comes from - for a reorder within this list and for an item coming in from another list alike, before anything is shown. A refused position keeps the item where it was, and the pointer shows that it cannot be dropped there. In swap mode it is asked about the dragged item alone, with the index of the item it would trade places with; a swap across lists also asks the list the dragged item is in about the item that would come back to it. A multi-drag asks once more on the drop, with the index the item takes once the rest of the selection gathers next to it: a refusal there puts every selected item back and ends the drag as cancelled. One that throws refuses the position it was asked about, and the exception is passed on once that step of the drag is done: thrown to the caller of MoveAsync or MoveToAsync, and raised as this list's own during a drag the user makes, for the nearest ErrorBoundary. Keep it fast and free of side effects: it runs while the pointer moves. Mirrors the SortableJS onMove option. | | ChildContent | `RenderFragment?` | null | Extra content rendered after the items, inside the list. It is rendered whether the list has items or not, after what an empty list shows, so it is not the place for an empty state: that is EmptyTemplate or EmptyText. | | Classes | `BitSortableClassStyles?` | null | Custom CSS classes for different parts of the sortable list. | | Clone | `Func<TItem, TItem>?` | null | The factory used to copy an item when Pull is Clone. Without one an item that is ICloneable is cloned, and any other one is shared, which is safe for values and strings. | | ConfirmDrop | `Func<BitSortableEventArgs<TItem>, Task<bool>>?` | null | Asked once an item has been dropped into this list - from this list or another one - whether to keep the move, for a check that has to wait (a server call, a confirmation dialog). The drop shows at once; the lists stay as dropped while the task runs, and no other drag starts until it completes. Return false to put every list the drag changed back as it was: ItemsChanged is raised for them (the page may have rendered them as dropped meanwhile), OnEnd reports Canceled, and no OnUpdate, OnAdd, OnRemove or OnSort is raised. Return true to keep it: the events follow as usual. Do not change the lists while it runs: a refusal puts back what they held before the drag. One that throws refuses the drop, and the exception is passed on once the drag is reported, as one CanDrop throws is. | | Delay | `int` | 0 | How long, in milliseconds, a mouse or pen press on an item must be held before it can be dragged; a pointer that moves further than DelayTolerance first is a click or a selection instead. The SortableJS delay option. | | DelayTolerance | `int` | 5 | How far, in pixels, the pointer may move while Delay or TouchDelay runs before the press is taken for a scroll or a click instead of a drag. The SortableJS touchStartThreshold option. | | Direction | `BitSortableDirection` | BitSortableDirection.Auto | The axis to sort along. Auto detects it from the layout; set it explicitly for grids. Mirrors the SortableJS direction option. | | EmptyTemplate | `RenderFragment?` | null | The template of what the list shows while it has no items. It takes precedence over EmptyText. | | EmptyText | `string?` | null | The text the list shows while it has no items. When null, the NoItemsFound text of the strings in force is used (BitStrings.NoItemsFound). | | Filter | `Func<TItem, bool>?` | null | A predicate returning true for the items that must not be dragged. The other items can still be dragged past a filtered item, which moves it along by one, so it does not pin an item to its index. | | ForceFallback | `bool` | false | When true, the mouse drags like a finger or a pen: with pointer events and a preview of the item that follows the pointer (BitSortableClassStyles.Drag), instead of the browser's own drag and its drag image - for a preview styled the app's way, or a web view whose native drag and drop does not work. A finger and a pen always drag this way. The SortableJS forceFallback option. | | Group | `string?` | null | The name of the group of lists that can exchange items: lists with the same group name take each other's items. | | Handle | `string?` | null | The CSS selector of a drag handle within each item. With a handle only the handle starts a drag, and the rest of the item keeps its normal pointer behavior (text selection, inputs, links). | | InvertedSwapThreshold | `double` | 0 | The fraction (0-1) of an item used for the inverted swap zone. Defaults to SwapThreshold when left at 0. Mirrors the SortableJS invertedSwapThreshold option. | | InvertSwap | `bool` | false | When true the swap zones sit at the item's edges instead of its center, giving a "sort between items" feel. Mirrors the SortableJS invertSwap option. | | IsolateItems | `bool` | false | Renders each item's template in a component of its own, rendered again only when the item, the template or the list's parameters change - not on every step of a drag, where only the item wrappers move. For long lists with costly templates. Leave it off when a template shows something that changes as other items move during a drag (an item's position, say): it is brought up to date only when the drag ends. | | ItemClass | `Func<TItem, string?>?` | null | The CSS class of an item's wrapper, chosen per item, which follows the item from list to list. | | ItemKey | `Func<TItem, object>?` | null | What identifies an item, e.g. card => card.Id: the value its element is keyed by (@key), by which the list finds it, tells it from the other items and keeps it selected. Give it when the page may replace the items with new instances of the same data - a list loaded again from a server - so that each item keeps its element, its focus and its selection; or when items compared by reference stand for records with an id. The key must be unique within the list and must not change while the item is in it, and a Clone factory has to give a copy a key of its own: a copy whose key is already in the target list is refused as a duplicate. A lambda written inline is fine: the list tells a new ItemKey by its code, not by the delegate instance a render creates. Without it an item is identified by itself, compared by its Equals. | | ItemLabel | `Func<TItem, string>?` | null | How the announcements name an item, e.g. card => card.Title. Without it an item is named by its ToString(). | | Items | `IList<TItem>?` | null | The list of items to display and reorder. Bind with @bind-Items. It must be a mutable list (e.g. List<T>), changed in place; a read-only one (such as an array) can only be dragged from in Clone mode. | | ItemsChanged | `EventCallback<IList<TItem>>` | | The callback raised with the list each time a drag changed it (supports @bind-Items). The list is the one Items holds, changed in place. | | ItemStyle | `Func<TItem, string?>?` | null | The inline style of an item's wrapper, chosen per item, which follows the item from list to list. | | ItemTemplate | `RenderFragment<TItem>?` | null | The template rendered for each item. | | Keyboard | `bool` | true | Lets the items be picked up, moved and dropped from the keyboard: an item is focusable (the list is one tab stop, and the arrow keys move between its items), Space or Enter picks it up, the arrow keys move it - within the list, and into the next list of the group in that direction - Home and End move it to the ends, Space or Enter drops it and Escape puts it back. Every step is announced to screen readers. | | MaxItems | `int?` | null | The most items this list holds: once it holds this many, it takes no item from another list (a multi-drag counts every item it carries). Reordering within the list, and swapping, are not affected. null sets no limit. | | MinItems | `int?` | null | The fewest items this list keeps: an item is not moved out to another list when that would leave fewer (a multi-drag counts every item it carries away). Reordering within the list, cloning out of it and swapping are not affected, and neither is a change the page makes to the list itself. null sets no limit. | | MultiDrag | `bool` | false | Enables the MultiDrag plugin behavior: click items to select several, then drag any one of them to move the whole selection together. Mirrors the SortableJS multiDrag option. | | OnAdd | `EventCallback<BitSortableEventArgs<TItem>>` | | The callback raised on the destination list when an item is dropped in from another list. | | OnChange | `EventCallback<BitSortableEventArgs<TItem>>` | | The callback raised while dragging, each time the dragged item moves to a new position in this list. | | OnEnd | `EventCallback<BitSortableEventArgs<TItem>>` | | The callback raised on the source list when a drag ends, whatever its outcome - also when it ends before it was released, because the source list left the page or the browser never reported its end. | | OnRemove | `EventCallback<BitSortableEventArgs<TItem>>` | | The callback raised on the source list when an item is moved out to another list. | | OnSort | `EventCallback<BitSortableEventArgs<TItem>>` | | The callback raised on every list whose items changed (add, remove or update). | | OnStart | `EventCallback<BitSortableEventArgs<TItem>>` | | The callback raised on this list when a drag starts in it. | | OnUpdate | `EventCallback<BitSortableEventArgs<TItem>>` | | The callback raised when the order of this list changed within the list. | | Pull | `BitSortablePull` | BitSortablePull.Move | Controls how items may be dragged out of this list, mirroring the SortableJS group.pull option. | | Put | `bool` | true | Whether items from other lists in the group may be dropped here. | | PutGroups | `IReadOnlyCollection<string>?` | null | Other groups whose items may be dropped into this list, besides its own Group: a trash or an archive list that takes the cards of several boards, say. It lets items in only - this list's own items still go only to the lists of its group, or to lists that name its group here - and Put, MaxItems, CanDrop and the item type apply as for any other drop. The SortableJS group.put option given a list of group names. | | RevertOnSpill | `bool` | false | When true, a drag that starts in this list and is released outside every list that takes it puts everything back where it was: a live reorder is undone, and an item previewed in another list returns home. The SortableJS revertOnSpill option. With the default false the drag keeps what it did, as in SortableJS: an item previewed in another list lands there wherever it is released. A drag cancelled with Escape where the list can tell (a keyboard drag, or a touch or pen drag) is always put back. | | Scroll | `bool` | true | Scrolls whatever the pointer is near the edge of - the list, a scrolling panel around it, the page - while a finger, a pen or a ForceFallback mouse drags an item, the innermost one that can still scroll that way first. A native mouse drag is scrolled by the browser itself. The SortableJS scroll option. | | ScrollSensitivity | `int` | 40 | How close, in pixels, the pointer must come to an edge to scroll (see Scroll). | | ScrollSpeed | `int` | 16 | The most pixels an edge scrolls per frame, reached at the very edge (see Scroll). | | SelectedItems | `IReadOnlyCollection<TItem>?` | null | The items selected for a multi-drag (MultiDrag), to read or set from the page: bind it with @bind-SelectedItems. Items that are not in the list, or that cannot be dragged, are left out. | | SelectedItemsChanged | `EventCallback<IReadOnlyCollection<TItem>>` | | The callback raised with the selection, in list order, when a click, Shift+click or Shift+Space changes it, or a drag spends or clears it (supports @bind-SelectedItems). | | Sort | `bool` | true | Allows reordering within this list. Set to false to only allow dragging out. | | Strings | `BitSortableStrings?` | null | The texts the list gives assistive technology - the keyboard instructions, how an item is described, and what is announced as items are picked up, moved, dropped or put back - to translate or reword them. When null, the English texts of a new BitSortableStrings are used. | | Styles | `BitSortableClassStyles?` | null | Custom CSS styles for different parts of the sortable list. | | Swap | `bool` | false | Enables the Swap plugin behavior: instead of sorting, the dragged item trades places with the item it is dropped on. While dragging, the item under the pointer is highlighted (BitSortableClassStyles.SwapTarget). Mirrors the SortableJS swap option. | | SwapThreshold | `double` | 1 | The fraction (0-1) of an item that acts as its swap zone, mirroring the SortableJS swapThreshold option. With the default 1 the whole item swaps; a smaller value (e.g. 0.65) leaves a dead zone near each edge, so the pointer has to move further into an item before the dragged one swaps past it. | | TouchDelay | `int` | 200 | How long, in milliseconds, a finger must rest on an item before it drags it - a long press - so that a swipe over the list still scrolls the page. A finger that moves further than DelayTolerance first scrolls. Set 0 with a Handle whose CSS has touch-action: none for a handle that drags at once. | | AriaLabel | `string?` | null | Gets or sets the accessible label for the component, used by assistive technologies. | | Class | `string?` | null | Gets or sets the CSS class name(s) to apply to the rendered element. | | Dir | `BitDir?` | null | Gets or sets the text directionality for the component's content. | | Disabled | `bool` | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. | | ForceAnimation | `bool` | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. | | HtmlAttributes | `Dictionary<string, object>` | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name. | | Id | `string?` | null | Gets or sets the unique identifier for the component's root element. | | Style | `string?` | null | Gets or sets the CSS style string to apply to the rendered element. | | TabIndex | `string?` | null | Gets or sets the tab order index for the component when navigating with the keyboard. | | Visibility | `BitVisibility` | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. | ## Public Members | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | MoveAsync | `Task<bool> MoveAsync(TItem item, int newIndex)` | | Moves the item to newIndex within this list, as a drag would: the list must allow it (Sort, Disabled, CanDrop), the destination's ConfirmDrop is asked, the items slide into place, and the drag's events follow, with Input set to Api. In swap mode the item trades places with the one at newIndex. Filter locks an item against the user's drags only, and a multi-drag selection is not carried along. It is the non-drag way to rearrange a list that an accessible app offers next to dragging: "move up", "move to top" buttons or an item menu. Returns true when the item moved; false when it is not in this list, the index is out of range or the item is already there, a drag is in progress, or a rule refused the move. | | MoveToAsync | `Task<bool> MoveToAsync(TItem item, string listId, int newIndex)` | | Moves the item from this list into the list whose id (its Id, or its UniqueId) is listId, at newIndex, as a drag would: the lists must exchange items (Group or the destination's PutGroups, Pull, Put, Disabled, the destination's MaxItems, this list's MinItems, the item type), the destination's CanDrop and ConfirmDrop are asked, a Clone source puts a copy there, and the drag's events follow with Input set to Api. Into a swap-mode list the item trades places with the one at newIndex. Returns true when the item moved; false when there is no such list, the item is not in this list, the index is out of range, a drag is in progress, or a rule refused the move. | | UniqueId | `Guid` | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. | | RootElement | `ElementReference` | | Gets the reference to the root HTML element associated with this component. | ## Enums ### BitSortableDirection Enum | Name | Value | Description | | :--- | :--- | :---------- | | Auto | 0 | Detect the axis automatically from the layout of the items. | | Horizontal | 1 | Sort along the horizontal (x) axis. | | Vertical | 2 | Sort along the vertical (y) axis. | ### BitSortableInput Enum | Name | Value | Description | | :--- | :--- | :---------- | | Mouse | 0 | A mouse (or a trackpad). | | Touch | 1 | A finger on a touch screen. | | Pen | 2 | A pen or stylus. | | Keyboard | 3 | The keyboard: the item was picked up, moved and dropped with keys. | | Api | 4 | Code: a move made through the list's methods, such as MoveAsync. | ### BitSortablePull Enum | Name | Value | Description | | :--- | :--- | :---------- | | Move | 0 | Items can be moved out of the list (the default). | | None | 1 | Items cannot be dragged out of the list. | | Clone | 2 | A copy of the item is placed in the target list; the original stays put. | ### BitVisibility Enum | Name | Value | Description | | :--- | :--- | :---------- | | Visible | 0 | The content of the component is visible. | | Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). | | Collapsed | 2 | The component is hidden (display:none). | ### BitDir Enum | Name | Value | Description | | :--- | :--- | :---------- | | Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). | | Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). | | Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. | ## Sub Classes ### BitSortableEventArgs<TItem> Properties The payload of the drag lifecycle callbacks (OnStart, OnEnd, OnAdd, OnRemove, OnUpdate, OnSort and OnChange) and of the CanDrop and ConfirmDrop questions. Mirrors the SortableJS event object. | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Item | `TItem` | | The item that was dragged. | | Items | `IReadOnlyList<TItem>` | [] | All items moved by this drag, in list order. For a multi-drag this is the whole selection (including Item); otherwise it contains just Item. Mirrors evt.items of the SortableJS MultiDrag plugin. | | OldIndex | `int` | | The item's index within its original list when the drag started. | | NewIndex | `int` | | The item's index within the destination list. | | FromId | `string` | "" | The id of the source list: its Id, or its UniqueId when it is given none. | | ToId | `string` | "" | The id of the destination list: its Id, or its UniqueId when it is given none. | | FromGroup | `string?` | null | The group name of the source list, if any. | | ToGroup | `string?` | null | The group name of the destination list, if any. | | CrossedLists | `bool` | | true when the item crossed from one list into another. | | Input | `BitSortableInput` | | How the drag was made: with a mouse, a finger, a pen, the keyboard, or by code. | | IsClone | `bool` | | true when the move puts a copy of the item into another list (the source's Pull is Clone) and the original stays. Item is then the copy in the events that follow the drop, and the original in the ones before it. | | Canceled | `bool` | | Set on OnEnd: true when the drag ended without keeping any change, and every list it touched was put back as it was. It was cancelled (Escape); released outside every list of a source with RevertOnSpill; refused by the destination's ConfirmDrop (or one that threw); a multi-drag whose gathering on the drop the destination's CanDrop refused (or threw on); or a drag whose list left the page before it was dropped, into a list with a ConfirmDrop, which cannot be asked then. | | IsSwap | `bool` | | true when the move is a swap: the dragged Item trades places with SwappedWith (a list in Swap mode). Set on the events of a committed swap and on the CanDrop questions about one. | | SwappedWith | `TItem?` | | In a swap (IsSwap), the item Item trades places with: it takes the place Item leaves - index OldIndex of the source list, unless a keyboard drag carried the item into another list first - so that a handler can save both moves. default for any other move: check IsSwap rather than this, as for an item of a value type default is an item too. | ### BitSortableStrings Properties All screen-reader-visible strings of a BitSortable: the keyboard instructions every item points to, how an item is described, and what is announced as an item is picked up, moved, dropped or put back. Assign a customized instance to the Strings parameter - or to a BitSortableParams cascaded by a BitParams - to translate or reword them; every property defaults to the English text. A list announces with the strings of the list a drag started in. The announcements are functions of a BitSortableAnnouncement rather than format strings, since what they say depends on more than the values they put in. | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Instructions | `string` | "To pick up the item, press Space or Enter. ..." | How to drag an item with the keyboard; every item refers to it (aria-describedby), so a screen reader reads it when an item is focused. | | SelectionInstructions | `string` | "Shift and Space select or deselect the item; ..." | Added to Instructions in a MultiDrag list: how to select several items from the keyboard. | | RoleDescription | `string` | "sortable item" | What an item is called in place of "list item" (aria-roledescription). | | PickedUp | `Func<BitSortableAnnouncement, string>` | | An item was picked up. | | Moved | `Func<BitSortableAnnouncement, string>` | | A picked-up item moved to a new position, or a move made by code moved an item. | | SwapTarget | `Func<BitSortableAnnouncement, string>` | | In swap mode, a picked-up item will trade places with Target when it is dropped. | | Dropped | `Func<BitSortableAnnouncement, string>` | | An item was dropped. | | Canceled | `Func<BitSortableAnnouncement, string>` | | A drag was cancelled, or its drop refused, and the item put back. | | Refused | `Func<BitSortableAnnouncement, string>` | | A position the item was moved toward is refused (a rule, a full list), or the item cannot be picked up. | | Locked | `Func<BitSortableAnnouncement, string>` | | An item that cannot be dragged (one Filter locks, or one of a disabled list) was asked to be picked up. | | Selected | `Func<BitSortableAnnouncement, string>` | | In a MultiDrag list, Shift+Space added an item to the selection. | | Deselected | `Func<BitSortableAnnouncement, string>` | | In a MultiDrag list, Shift+Space took an item out of the selection. | ### BitSortableAnnouncement Properties What a BitSortableStrings text is about: the item, and where it is. | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Item | `string` | | The item, as ItemLabel names it. | | Position | `int` | | Its position now, counted from 1. | | Count | `int` | | How many items the list it is in holds. | | List | `string?` | | The list it is in, as its AriaLabel names it; null when it has none. | | OldPosition | `int` | | Its position when it was picked up, counted from 1. | | FromList | `string?` | | The list it was picked up from, as its AriaLabel names it. | | Returned | `bool` | | Whether it is back where it was picked up: in the same list (not merely one with the same name, or none), at the same position. | | Target | `string?` | | In swap mode, the item it will trade places with; otherwise null. | | Selected | `int` | | For Selected and Deselected: how many items are selected now. | ### BitSortableClassStyles Properties | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Root | `string?` | null | Custom CSS classes/styles for the root element of the BitSortable. | | Item | `string?` | null | Custom CSS classes/styles for every item wrapper of the BitSortable. | | Ghost | `string?` | null | Custom CSS classes/styles for the item being dragged, and for the drop preview shown in another list. | | Chosen | `string?` | null | Custom CSS classes/styles for the item picked up. | | SwapTarget | `string?` | null | Custom CSS classes/styles for the item highlighted as the swap target while dragging in swap mode. | | Selected | `string?` | null | Custom CSS classes/styles for the items of a MultiDrag selection. | | Filtered | `string?` | null | Custom CSS classes/styles for the items the Filter locks. | | Drag | `string?` | null | Custom CSS classes/styles for the preview of the item that follows a finger, a pen, or the mouse with ForceFallback, which is placed above the page. | | Empty | `string?` | null | Custom CSS classes/styles for what an empty list shows. | ## CSS Variables Public CSS custom properties read off the component's root. Set one on `:root` to restyle every instance, on any ancestor to restyle the ones inside it, or on the `Style` of one instance to restyle it and every instance nested inside it, which inherits the value too - a parameter changes one alone, as does the real CSS property on its `Style` / `Styles` when that property does not inherit (`opacity`); an inherited one (`color`, `font-family`) reaches the nested instances that do not set it themselves. | Name | Default Value | Description | | :--- | :------------ | :---------- | | `--bit-Sortable-ghost-opacity` | 0.4 | Opacity of the item being dragged, and of the drop preview shown in another list. | | `--bit-Sortable-chosen-background` | --bit-clr-bg-pri-hover | Background of the item picked up. | | `--bit-Sortable-selected-background` | --bit-clr-pri-light | Background of an item of a MultiDrag selection. | | `--bit-Sortable-selected-ring-color` | --bit-clr-pri | The ring around an item of a MultiDrag selection. | | `--bit-Sortable-swap-background` | --bit-clr-pri-light | Background of the item a dragged one would trade places with, in swap mode. | | `--bit-Sortable-swap-outline-color` | --bit-clr-pri | The dashed outline of the item a dragged one would trade places with. | | `--bit-Sortable-filtered-opacity` | 1 | Opacity of an item the Filter locks. Not dimmed by default: the item's content stays live, and a faded item would fall below the contrast its text needs. | | `--bit-Sortable-drag-opacity` | 0.92 | Opacity of the preview that follows a finger, a pen or a ForceFallback mouse. The preview is placed above the page, outside the list, so only a value set on :root (or an ancestor of the body) reaches it. | | `--bit-Sortable-drag-shadow` | --bit-shd-popup | Shadow of the preview that follows a finger, a pen or a ForceFallback mouse; set it on :root. | | `--bit-Sortable-count-background` | --bit-clr-pri | Background of the count a multi-drag's picture carries; set it on :root, as the picture is placed above the page. | | `--bit-Sortable-count-color` | --bit-clr-pri-text | Text of the count a multi-drag's picture carries. | | `--bit-Sortable-accepts-outline` | none | Outline of a list that takes the drag in progress. | | `--bit-Sortable-over-outline` | none | Outline of the list under the pointer. | | `--bit-Sortable-refused-outline` | none | Outline of the list under the pointer that refused the position. | | `--bit-Sortable-target-offset` | 2px | The offset of the accepts, over and refused outlines. | | `--bit-Sortable-empty-padding` | spacing(2) | Padding of what an empty list shows. | | `--bit-Sortable-empty-color` | --bit-clr-fg-sec | Text of what an empty list shows. | ## Examples \n**Basic**: ```razor
@item
Order: @string.Join(", ", basicItems)
``` ```csharp private IList basicItems = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]; ``` \n**Animation**: ```razor
@item
``` ```csharp private double animation = 150; private IList animationItems = ["Apples", "Bread", "Cheese", "Dates", "Eggs"]; ``` \n**Group**: ```razor
List A
@item
List B
@item
A: @string.Join(", ", groupA)
B: @string.Join(", ", groupB)
``` ```csharp private IList groupA = ["A1", "A2", "A3", "A4"]; private IList groupB = ["B1", "B2", "B3", "B4"]; ``` \n**EmptyText & EmptyTemplate**: ```razor
Inbox
@item
Archive
@item
Nothing archived yet - drop a message here.
Spam
@item
``` ```csharp private IList inbox = ["Invoice", "Newsletter", "Meeting notes"]; private IList mailArchive = []; private IList spam = []; ``` \n**Clone**: ```razor
Palette
@field.Name
Form
@field.Name
Form: @string.Join(", ", form.Select(f => f.Name))
``` ```csharp // A read-only list: it is shown and cloned from, but never sorted, pulled from or dropped into. private readonly FormField[] palette = [new("Text box"), new("Checkbox"), new("Drop-down"), new("Date")]; private IList form = []; // A class, not a record: two copies of the same field must not be equal, since a list holds an item once. public sealed class FormField(string name) { public string Name { get; } = name; } ``` \n**Sort, Put & Pull**: ```razor
Pick from (no Sort, no Put)
@item
Pinned (Pull None)
@item
Target
@item
``` ```csharp private IList pickFrom = ["Pick 1", "Pick 2", "Pick 3"]; private IList pinned = ["Rent", "Groceries"]; private IList target = ["Gym", "Books"]; ``` \n**Disabled**: ```razor
Archive
@item
Desk
@item
``` ```csharp private bool archiveDisabled = true; private IList archive = ["2024 report", "2025 report"]; private IList desk = ["Draft", "Notes"]; ``` \n**Handle**: ```razor
Steps: @string.Join(", ", steps.Select(s => s.Done ? $"{s.Text} (done)" : s.Text))
``` ```csharp private IList steps = [ new() { Text = "Pack the tent" }, new() { Text = "Check the weather", Done = true }, new() { Text = "Fill the water bottles" }, new() { Text = "Charge the torch" }, ]; public sealed class ChecklistStep { public required string Text { get; set; } public bool Done { get; set; } } ``` \n**Filter**: ```razor
@task.Title
``` ```csharp private IList tasks = [ new() { Title = "Write the tests" }, new() { Title = "Release notes", Locked = true }, new() { Title = "Deploy" }, new() { Title = "Announce" }, ]; public sealed class LockableTask { public required string Title { get; init; } public bool Locked { get; set; } } ``` \n**Swap thresholds**: ```razor
@item
``` ```csharp private double swapThreshold = 0.65; private bool invertSwap; private double invertedSwapThreshold = 0.65; private IList thresholdItems = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]; // The zones are drawn by the page's stylesheet, from these two custom properties. private string ZoneStyle => string.Create(CultureInfo.InvariantCulture, $"--zone:{swapThreshold:0.00};--inverted-zone:{invertedSwapThreshold:0.00}"); ``` \n**Grid & horizontal lists**: ```razor
@number

@tag
``` ```csharp private IList numbers = Enumerable.Range(1, 12).ToList(); private IList tags = ["blazor", "dotnet", "drag-and-drop", "sortable", "css", "a11y"]; ``` `BitSortableDemo.razor.scss`: ```scss // The lists are laid out from a plain element of the page, which carries its scope attribute. .grid ::deep .bit-srt { gap: 0.5rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(3.5rem, 1fr)); } .strip ::deep .bit-srt { gap: 0.5rem; display: flex; flex-wrap: wrap; } .tile { display: grid; aspect-ratio: 1; place-items: center; border-radius: 0.25rem; background-color: var(--bit-clr-bg-sec); border: 1px solid var(--bit-clr-brd-pri); } .chip { padding: 0.25rem 0.75rem; border-radius: 1rem; border: 1px solid var(--bit-clr-brd-pri); } ``` \n**Nested lists**: ```razor
@NestedList(tree)
Tree: @Describe(tree)
``` ```csharp // A list inside every item: each level shares the group, so an item moves from branch to branch with its children. private RenderFragment NestedList(IList nodes) => @
@node.Name
@NestedList(node.Children)
; private IList tree = [ new("Item 1.1", [new("Item 2.1"), new("Item 2.2", [new("Item 3.1"), new("Item 3.2")]), new("Item 2.3")]), new("Item 1.2"), new("Item 1.3", [new("Item 2.4"), new("Item 2.5")]), new("Item 1.4"), ]; // "Item 1.1 [Item 2.1, Item 2.2 [Item 3.1, Item 3.2]], Item 1.2": every item, its children in brackets. private static string Describe(IList nodes) => string.Join(", ", nodes.Select(n => n.Children.Count == 0 ? n.Name : $"{n.Name} [{Describe(n.Children)}]")); public sealed class TreeNode(string name, List? children = null) { public string Name { get; } = name; public IList Children { get; } = children ?? []; } ``` \n**PutGroups**: ```razor
Tasks
@item
Bugs
@item
Trash
@item
``` ```csharp private IList todo = ["Write the docs", "Plan the release", "Tidy the backlog"]; private IList bugs = ["Crash on save", "Typo in the footer"]; private IList trash = []; ``` \n**MaxItems & MinItems**: ```razor
Pipeline (at least 2)
@item
Shelf (at most 3)
@item
``` ```csharp private IList pipeline = ["Build", "Test", "Deploy"]; private IList shelf = ["Lint", "Benchmark"]; ``` \n**CanDrop, ConfirmDrop & RevertOnSpill**: ```razor
To do
@item
In progress
@item
Done (from In progress)
@item
Server: @serverStatus
``` ```csharp private bool approve = true; private string serverStatus = "idle"; private IList boardTodo = ["Write the spec", "Draw the icons", "Plan the launch"]; private IList boardDoing = ["Build the API", "Review the PR"]; private IList boardDone = ["Set up CI"]; // The script marks the lists that take a drag, the one under the pointer and one that refused the position; the // public variables, set on an ancestor of the board, draw them. private const string boardOutlines = "--bit-Sortable-accepts-outline:2px dashed var(--bit-clr-pri);" + "--bit-Sortable-over-outline:2px solid var(--bit-clr-pri);" + "--bit-Sortable-refused-outline:2px solid var(--bit-clr-err);"; // Done takes the cards of In progress, and its own. private bool CanDropInDone(BitSortableEventArgs e) => e.FromId is "board-doing" or "board-done"; // Stands in for a call to a server that may refuse the move. private async Task ConfirmDoneAsync(BitSortableEventArgs e) { serverStatus = $"asking about {e.Item}..."; StateHasChanged(); await Task.Delay(500); serverStatus = approve ? $"saved {e.Item}" : $"refused {e.Item}"; StateHasChanged(); return approve; } ``` \n**MoveAsync & MoveToAsync**: ```razor
Backlog
@item
Sprint
@item
``` ```csharp private BitSortable backlogList = default!; private BitSortable sprintList = default!; private IList backlog = ["Sign-up page", "Password reset", "Audit log", "Dark mode"]; private IList sprint = ["Search", "Export to CSV"]; ``` \n**Swap**: ```razor
@item
Order: @string.Join(", ", swapItems)
Last swap: @lastSwap

Left
@item
Right
@item
``` ```csharp private string lastSwap = "nothing yet"; private IList swapItems = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]; private IList swapLeft = ["Item 1", "Item 2", "Item 3"]; private IList swapRight = ["Item A", "Item B", "Item C"]; // SwappedWith names the item the dragged one traded places with: both moves, for a handler that saves them. private void HandleSwap(BitSortableEventArgs e) { lastSwap = e.IsSwap ? $"{e.Item} and {e.SwappedWith}" : $"{e.Item} moved"; } ``` \n**MultiDrag**: ```razor
Select all Clear the selection
@item
Selected: @(selectedItems.Count == 0 ? "nothing" : string.Join(", ", selectedItems))

Left
@item
Right
@item
``` ```csharp private IList multiItems = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]; private IReadOnlyCollection selectedItems = []; private IList multiLeft = ["Item 1", "Item 2", "Item 3", "Item 4"]; private IList multiRight = ["Item A", "Item B"]; ``` \n**Events**: ```razor
Clear the log
events-left
@item
events-right
@item
@if (eventLog.Count == 0) {
No events yet.
} @foreach (var line in eventLog) {
@line
}
``` ```csharp private bool logChange; private readonly List eventLog = []; private IList eventsLeft = ["Item 1", "Item 2", "Item 3", "Item 4"]; private IList eventsRight = ["Item A", "Item B"]; // "[OnAdd @events-right] Item 4: events-left#3 -> events-right#0 (mouse)": the event, the list that raised it, the // item, where it came from and where it went, how it was dragged and the flags that are set. private void Log(string name, string list, BitSortableEventArgs e) { if (name == "OnChange" && logChange is false) return; var flags = string.Join(", ", new[] { e.Input.ToString().ToLowerInvariant(), e.IsClone ? "clone" : null, e.Canceled ? "canceled" : null }.OfType()); eventLog.Insert(0, $"[{name} @{list}] {e.Item}: {e.FromId}#{e.OldIndex} -> {e.ToId}#{e.NewIndex} ({flags})"); if (eventLog.Count > 30) eventLog.RemoveAt(eventLog.Count - 1); } ``` \n**Keyboard & Strings**: ```razor
Backlog
#@ticket.Id @ticket.Title
Sprint
#@ticket.Id @ticket.Title
``` ```csharp private bool keyboard = true; private bool german; private IList ticketBacklog = [new(1, "Sign-up page"), new(2, "Password reset"), new(3, "Audit log")]; private IList ticketSprint = [new(4, "Search"), new(5, "Export to CSV")]; private sealed record Ticket(int Id, string Title); private static string In(string? list) => list is null ? "" : $" in {list}"; private readonly BitSortableStrings germanStrings = new() { Instructions = "Leertaste oder Eingabetaste nimmt das Element auf. Danach verschieben es die Pfeiltasten, Pos1 und Ende an den " + "Anfang oder das Ende der Liste, Leertaste oder Eingabetaste legt es ab, und Escape bringt es zurück.", SelectionInstructions = "Umschalt und Leertaste wählen das Element aus oder ab; ein ausgewähltes Element nimmt die ganze Auswahl mit.", RoleDescription = "sortierbares Element", PickedUp = a => $"{a.Item} aufgenommen. Position {a.Position} von {a.Count}{In(a.List)}.", Moved = a => $"{a.Item} auf Position {a.Position} von {a.Count}{In(a.List)} verschoben.", SwapTarget = a => a.Target is null ? $"{a.Item} bleibt, wo es ist." : $"{a.Item} tauscht den Platz mit {a.Target}.", Dropped = a => a.Returned ? $"{a.Item} abgelegt. Wieder auf Position {a.Position} von {a.Count}{In(a.List)}." : $"{a.Item} auf Position {a.Position} von {a.Count}{In(a.List)} abgelegt.", Canceled = a => $"Abgebrochen. {a.Item} ist wieder auf Position {a.Position} von {a.Count}{In(a.List)}.", Refused = a => $"{a.Item} kann nicht dorthin verschoben werden.", Locked = a => $"{a.Item} kann nicht verschoben werden.", Selected = a => $"{a.Item} ausgewählt. {a.Selected} ausgewählt.", Deselected = a => $"{a.Item} abgewählt. {a.Selected} ausgewählt.", }; ``` \n**Touch & pen**: ```razor
Long press
@item
Handle, at once
@item
``` ```csharp private double touchDelay = 200; private double delay; private double delayTolerance = 5; private bool forceFallback; private IList groceries = ["Kale", "Lemons", "Milk", "Nuts", "Oats"]; private IList chores = ["Dishes", "Laundry", "Plants", "Recycling"]; ``` `BitSortableDemo.razor.scss`: ```scss // The handle is rendered by the list's item template: reached through ::deep. The browser never scrolls from it, so // with TouchDelay="0" a finger on it drags at once. ::deep .handle { cursor: grab; touch-action: none; } ``` \n**Large list**: ```razor
@row.Name @row.Note
``` ```csharp private bool isolateItems; private bool largeForceFallback; private bool scroll = true; private double scrollSensitivity = 40; private double scrollSpeed = 16; private IList rows = Enumerable.Range(1, 300) .Select(i => new LargeRow($"Row {i}", i % 3 == 0 ? "blocked" : i % 2 == 0 ? "in review" : "open")) .ToList(); private sealed record LargeRow(string Name, string Note); ``` \n**ItemKey**: ```razor
Load the rows again
@row.Title
Loaded @loads time(s)
``` ```csharp private static readonly Func byId = row => row.Id; private bool keyById = true; private int loads = 1; private IList taskRows = [new(1, "Write the spec"), new(2, "Review the design"), new(3, "Build the API"), new(4, "Ship it")]; // What a refresh from the server does: the same rows, in the order last saved, as new objects. private void ReloadRows() { taskRows = taskRows.Select(row => new TaskRow(row.Id, row.Title)).ToList(); loads++; } // A row as a server sends it: a class, so two loads of the same row are two different objects. public sealed class TaskRow(int id, string title) { public int Id { get; } = id; public string Title { get; } = title; } ``` \n**Cascading parameters**: ```razor
@item
@item
``` ```csharp private readonly BitSortableParams[] sortableParams = [ new() { Animation = 600, EmptyText = "Nothing here - drop an item." } ]; private IList paramsFirst = ["One", "Two", "Three"]; private IList paramsSecond = []; ``` \n**Style & Class**: ```razor
Style & Class
@item
Styles & Classes
@item
ItemStyle
@item

@item
@item
``` ```csharp private const string cssVariablesStyle = "--bit-Sortable-ghost-opacity:0.15;" + "--bit-Sortable-chosen-background:var(--bit-clr-bg-sec);" + "--bit-Sortable-accepts-outline:2px dashed var(--bit-clr-pri);" + "--bit-Sortable-over-outline:2px solid var(--bit-clr-pri);"; private IList styledItems = ["Styled 1", "Styled 2", "Styled 3"]; private IList classedItems = ["Classy 1", "Classy 2", "Classy 3"]; private IList itemStyled = ["Ordinary", "Important", "Routine"]; private IList fruits = ["Apple", "Banana", "Cherry"]; private IList basket = ["Fig", "Grape"]; ``` \n**RTL**: ```razor
@step
ترتیب: @string.Join("، ", rtlSteps)
``` ```csharp private IList rtlSteps = ["گام ۱", "گام ۲", "گام ۳", "گام ۴", "گام ۵"]; ```