Skip to content

Extras

Sortable

Bit.BlazorUI.ExtrasSortableListReorderableListDragAndDropList

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.

Notes

To use this component, you need to install the Bit.BlazorUI.Extras(opens in a new tab) nuget package, as described in the Optional steps of the Getting started page.

The list needs no service of its own: lists exchange items through a coordinator they share per scope - one per circuit on Blazor Server, one per app on WebAssembly - so two users never share a drag. It changes the page's own IList in place and raises ItemsChanged once a drag changed it, so it is bound with @bind-Items to a field declared as an IList<TItem> (a List<TItem>, or any list that is not read-only); a field of another type does not compile with @bind-Items. Its items are told apart the way @key tells them apart - by their Equals, or by the key ItemKey gives them - so a list must not hold the same item twice. The look of the list and its items is the page's: the component's stylesheet only draws the drag states.

The sorting engine is C#, not SortableJS behind JavaScript interop: which list takes an item, what a position means, every change to the bound lists and every event are decided in .NET, and Blazor renders the result - nothing moves the DOM behind its back, so there is nothing to reconcile. The script of the component does what has to happen where the pointer is: it follows the drag, measures the pointer against the items, plays the slide animations, and calls .NET only when the drop position changes, so a drag stays smooth on Blazor Server too. Every item is wrapped in an element of the list, rendered with @key, that carries the drag; ItemTemplate renders inside it. When an item moves, Blazor moves its existing element, which keeps the browser's drag alive while the list reorders under it.

A list drags only on a page that renders interactively - WebAssembly, Server, Auto or Hybrid. A statically rendered page shows the items but never drags them; a prerendered one shows them at once and starts dragging as soon as it is interactive.

When something does not work: items that render but never drag are on a page that is not interactive. An item that another list does not take needs both lists in the same Group (or the target's PutGroups naming the source's group) and of the same TItem, a source whose Pull is not None and that is not at its MinItems, and a target with Put that is neither Disabled, full (MaxItems) nor read-only and does not already hold an equal item (or one with the same ItemKey). Drag states that are not drawn - the dragged item not dimmed, the original not hidden while it is previewed in another list - mean the Extras stylesheet is not linked.

Usage

Every example is live. Open its code to see exactly what produced the component running underneath.

Basic

Bind the list with @bind-Items and render each item with ItemTemplate. Drag an item: the list reorders live as the pointer moves, the other items slide out of its way, and the bound list is changed in place, so the order a user makes is the order the page reads back. ItemsChanged is raised once per drag, after the drop, and only when the order actually changed: a drag that ends where it started raises nothing.
  • Drag Item 1 down past Item 3: it moves as soon as the pointer enters the next item, and the order below changes when it is dropped.
  • Without a mouse: Tab into the list, pick the focused item up with Space, move it with the arrow keys, and drop it with Space - or put it back with Escape (see Keyboard & Strings).
  • On a touch screen, rest a finger on an item for a moment to pick it up; a quick swipe still scrolls the page (see Touch & pen).

Item 1
Item 2
Item 3
Item 4
Item 5
Order: Item 1, Item 2, Item 3, Item 4, Item 5

Animation

Animation is how long, in milliseconds, the items take to slide into their new places (150 by default); 0 turns the slide off. Before each change the list records where every item is, lets Blazor update the page, then slides each item from its old place to its new one (the FLIP technique). A move that starts while a slide is still running picks it up from where the item is, so nothing jumps. Like every animation of the library it follows the reduced-motion preference: with the system's setting on, nothing slides. Move the slider to 1000 to watch the slide in slow motion.

Apples
Bread
Cheese
Dates
Eggs

Group

Lists with the same Group exchange items: drag an item from one list onto an item of the other, or into its empty space. While it is over the other list a placeholder shows where it will land. ItemClass gives an item's wrapper a class chosen per item, which follows the item from list to list - the B items keep their mark wherever they go, and so does the placeholder.
  • Over another list the item is not moved yet: that list renders a placeholder - the item's own template, with the ghost look - where it would land, and the source hides its original. The item moves between the lists when the drag ends, since moving an element from one component to another would recreate it and cancel the browser's drag. A keyboard drag moves the item itself.
  • Drag an item over the other list, then back over its own: the preview goes away and the item is home again. Released with the mouse outside every list, an item previewed in another one lands there, as in SortableJS; RevertOnSpill puts it back instead (see CanDrop, ConfirmDrop & RevertOnSpill).
  • An item is only offered to lists of its own TItem, and never to a list that already holds an equal item - two lists of strings cannot both hold "A1". Lists of other item types may share the group: they ignore each other's items.
  • Each list that a drop changed raises its own ItemsChanged once. Give the lists an Id when the page needs to tell them apart: the events report it as FromId and ToId.

List A
A1
A2
A3
A4
List B
B1
B2
B3
B4
A: A1, A2, A3, A4
B: B1, B2, B3, B4

EmptyText & EmptyTemplate

A list with no items says so, and still takes a drop. EmptyTemplate is what it shows then, EmptyText a text in its place, and with neither it shows the NoItemsFound text of BitStrings. What an empty list shows is the one entry of the list while it has no items, which keeps an empty list tall enough to drop an item into and is read as part of it; it gives way to the placeholder while the list previews an item. ChildContent, rendered after the items whether there are any or not, is not the place for an empty state. Move every message out of the Inbox, then drag them back.

Inbox
Invoice
Newsletter
Meeting notes
Archive
Nothing archived yet - drop a message here.
Spam
No items found

Clone

With Pull set to Clone, what leaves a list is a copy and the original stays, so the same item can be dragged out again and again; with the mouse, the cursor shows a copy while the item is over another list. The Clone factory makes the copy; without one an ICloneable item is cloned and any other is shared. The palette here is a plain array: a read-only list - an array, a ReadOnlyCollection<T>, an ImmutableList<T> - is shown and cloned from, but never sorted, pulled from or dropped into, so it needs no Sort or Put of its own and is bound one way, with Items. A clone source that is a mutable list still sorts within itself and takes items back: only what leaves it is a copy, and what is dragged out of the form moves as usual.
  • The copy must be a distinct item: a list holds an item once, so a copy that equals an item already in the target is refused. That is why the fields here are a class, compared by reference - two records with the same values would be equal, and the second one refused - and why a shared item works for an immutable reference type but not for the same string twice. With ItemKey, the factory gives a copy a key of its own.
  • In the events that follow the drop, Item is the copy and IsClone is true, and OnRemove is not raised: nothing left the source.
  • Combined with Swap, a clone source gives its item itself away in the swap rather than a copy; combined with MultiDrag, dragging into another list clones only the dragged item.

Palette
Text box
Checkbox
Drop-down
Date
Form
Drag fields from the palette.
Form:

Sort, Put & Pull

Each list says what it allows. Sort set to false keeps its own order, Put set to false refuses the items of other lists, and Pull set to None keeps its items in it while it still sorts and takes items in. The items of the first list can only be dragged out; those of the second never leave.
  • Sort="false": no reordering within, items still drag out, and items of other lists still drop in where they are dropped - Sort keeps the list's own items in their order, it does not refuse others.
  • Put="false": reorders within and drags out, but takes nothing in.
  • Pull="BitSortablePull.None": reorders within and takes items in, but nothing drags out.
  • Pull="BitSortablePull.Clone": reorders within and takes items in, and what drags out is a copy (see Clone).
  • Disabled: none of these (see Disabled).
  • A read-only list, such as an array, behaves as if it had Sort="false", Put="false" and a Pull of None - except that a Clone pull still copies from it.
  • Try it: drag Pick 1 down its list - nothing moves; drag it into Target - it goes; drag it back - the first list does not take it. Drag Gym into Pinned: it goes in, and now it stays there.

Pick from (no Sort, no Put)
Pick 1
Pick 2
Pick 3
Pinned (Pull None)
Rent
Groceries
Target
Gym
Books

Disabled

A Disabled list takes part in no drag: its items cannot be picked up - by the mouse, a finger or the keyboard - and nothing is dropped into it. Its items are no longer a tab stop, and its root carries the bit-dis class, the one hook for a disabled component. What its items render stays live. Use it to lock a list while, say, its contents are being saved; to lock single items instead, see Filter.

Archive
2024 report
2025 report
Desk
Draft
Notes

Handle

Handle is the CSS selector of a drag handle inside each item. Only the handle starts a drag, and the rest of the item keeps its own pointer behavior - its text can be selected, its inputs typed into, its buttons clicked; here a checkbox that is checked with a click. A tick travels with its step, since it lives in the item.
  • With a Handle the items render as not draggable; pressing an element that matches the selector makes its item draggable for the drag that follows. The root gets the bit-srt-hnd class, which takes the grab cursor and the no-select rule off the rest of the item, so give the handle a grab cursor of its own (this page's handle class does).
  • From the keyboard nothing changes: Tab reaches the item (not the control inside it) and Space picks it up, while keys pressed inside a control are the control's. For a handle a keyboard user reaches as well, make it a button type="button" with an accessible name: it picks its item up too.
  • On a touch screen a handle still needs the long press, unless TouchDelay is 0 and the handle has touch-action: none (see Touch & pen).
  • A handle belongs to the item it sits in: in nested lists, a handle of an inner item never drags the outer item around it. A selector that is not valid CSS breaks nothing: the script warns once in the console, and no item drags.

Steps: Pack the tent, Check the weather (done), Fill the water bottles, Charge the torch

Filter

Filter is asked about every item, and an item it returns true for cannot be picked up - by the mouse, a finger or the keyboard. It does not pin the item to its index: the other items can still be dragged past it, which shifts it along by one, as in SortableJS. Here it reads a flag of the task, which the button of the task toggles; a click on a control inside an item is the control's, and never starts a drag.
  • Filter is a predicate on the typed item, not a CSS selector as in SortableJS, so the rule lives next to the data it reads, and a lock follows the data.
  • A locked item gets the not-allowed cursor and the Filtered part (Classes.Filtered, Styles.Filtered). It is not dimmed by default, since its content stays live; --bit-Sortable-filtered-opacity fades it.
  • From the keyboard, Space on a locked item announces the Locked text of the strings ("Release notes cannot be moved.").
  • It locks an item against the user's drags only: a move made by code (MoveAsync, MoveToAsync) still moves it, and in a MultiDrag list a locked item cannot be selected. To lock a whole list, see Disabled.

Write the tests
Release notes
Deploy
Announce

Swap thresholds

SwapThreshold is the part of an item, across its middle, that the pointer has to reach before the dragged item swaps past it; a smaller one leaves a dead zone near each edge. InvertSwap moves the zones to the edges of the item, InvertedSwapThreshold wide, for a sort-between-items feel. Direction says along which axis the zones run. The tinted bands show the zones. This mirrors the SortableJS thresholds demo.
  • Set SwapThreshold to 1: the whole item is the zone, and the dragged item swaps as soon as the pointer enters the next one. Set it to 0.2: the pointer has to reach the thin band in the middle, and the edges around it do nothing.
  • Turn InvertSwap on: entering the top or bottom band of an item puts the dragged one before or after it - a "drop between the items" feel. InvertedSwapThreshold sizes the two edge bands together; left at 0 it takes SwapThreshold.
  • Swap an item past the next one and move the pointer back a little: the area the dragged item has just left - its shadow - swaps it back. That rule, ported from SortableJS, keeps a short item and a tall one from trading places back and forth while the pointer sits still.
  • An item that enters a list it is not in yet always uses the inverted zones, whatever InvertSwap says, so it can be dropped before the first item as easily as after the last.

Item 1
Item 2
Item 3
Item 4
Item 5

Grid & horizontal lists

The list does not mind its layout: laid out as a CSS grid it is a sortable grid, as a wrapping row a horizontal list. Its items are measured as they are laid out, so a grid sorts across a row and from row to row. The default Direction, Auto, tells the axis from the layout; the row of tags sets it.
  • Auto reads the first two items: side by side is horizontal, anything else vertical. With a single item in view it reads the list instead: a flex row, or a grid of several columns, is horizontal, a flex column vertical. Set Direction when the layout says otherwise - in a grid, whose first two items sit side by side although the list also runs down.
  • The hit test is two-dimensional, so a grid sorts in every direction whatever Direction says: Direction only decides which way an item's swap zones run (see Swap thresholds).
  • The item wrappers are the direct children of the list's root, so the grid or the flex row lays them out: style them with ItemClass or Classes.Item, or style the template inside them. A list reversed with flex-direction: row-reverse or column-reverse is measured in its own order, as a right-to-left one is.
  • Drag square 1 onto square 7, a row down: it sorts across rows, not only along one. From the keyboard the arrows follow the layout: left and right along a row, up and down from row to row.

1
2
3
4
5
6
7
8
9
10
11
12

blazor
dotnet
drag-and-drop
sortable
css
a11y

Nested lists

A list can render another one inside each of its items. Every level shares the group, so an item - with its children - moves from branch to branch and from depth to depth. Each item renders a list of its own, empty or not, so any item can take children. Each list is bound one way, with Items, to its item's children, which it changes in place; ItemsChanged only tells the page to render the tree again. SwapThreshold 0.65 is the value the SortableJS nested demo uses: the outer part of each item is a dead zone.
  • An item is never dropped inside itself: the lists in the dragged item's own subtree, and those inside the drop preview, refuse it - drag Item 1.1 over its own children and none takes it.
  • Each list handles its own items only: a drag that starts in an inner list is not also a drag of the outer item around it.
  • A nested list takes the pointer only for a drag it could receive. One of another group, of another item type, or with Put="false" leaves the drag to the list around it - which is how the columns of a board still sort while the pointer crosses the card lists inside them.
  • From the keyboard, the arrows carry a picked-up item into a nested list and out again, in the direction they point.

Item 1.1
Item 2.1
Item 2.2
Item 3.1
Item 3.2
Item 2.3
Item 1.2
Item 1.3
Item 2.4
Item 2.5
Item 1.4
Tree: Item 1.1 [Item 2.1, Item 2.2 [Item 3.1, Item 3.2], Item 2.3], Item 1.2, Item 1.3 [Item 2.4, Item 2.5], Item 1.4

PutGroups

PutGroups names the groups whose items a list takes besides its own. Tasks and Bugs are groups of their own and never exchange items, while the Trash takes both. It lets items in only: what is in the Trash stays there. Put, MaxItems, CanDrop and the item type apply to those items as to any other drop, and the events' FromGroup says which group an item came from.

Tasks
Write the docs
Plan the release
Tidy the backlog
Bugs
Crash on save
Typo in the footer
Trash
Drop a task or a bug here.

MaxItems & MinItems

MaxItems is the most items a list holds: once full, it takes nothing from other lists - the pointer passes over it to the list around it, or shows that it cannot drop. MinItems is the fewest it keeps: nothing is moved out of it that would leave fewer, and the other lists do not take the drag, as if they were full. Both lists still sort their own items; a list at its minimum still clones out and swaps, none of which empties it. A multi-drag counts every item it carries, and a swap brings one item and takes one, so it is never refused for room. Drag Deploy to the Shelf - it goes, and two steps are left; Test then stays in the pipeline until a step comes back.

Pipeline (at least 2)
Build
Test
Deploy
Shelf (at most 3)
Lint
Benchmark

CanDrop, ConfirmDrop & RevertOnSpill

CanDrop is asked, as the dragged item reaches a position, whether it may take it - here Done takes cards from In progress only (FromId is the Id of the list the item comes from). ConfirmDrop is asked once the item is dropped, for a check that has to wait: refused, every list goes back as it was. With RevertOnSpill, a card released outside every list that takes it goes back where it came from.
  • CanDrop is the SortableJS onMove: it is asked for a reorder within the list and for an item coming from another list alike, before anything is shown, with the proposed move - Item (and Items for a multi-drag), FromId and FromGroup, OldIndex, and NewIndex, the index the item would have here. Refused, the item stays where it was, nothing is previewed, and the pointer shows that it cannot drop. It runs while the pointer moves: keep it fast and free of side effects.
  • ConfirmDrop lets a server or a dialog have the last word. The drop shows at once and the lists stay as dropped while it runs, and no other drag starts until it answers. True keeps the move, and the usual events follow. False - or a task that throws - slides every list the drag changed back, raises ItemsChanged for them, and OnEnd reports Canceled, with no OnUpdate, OnAdd, OnRemove or OnSort.
  • RevertOnSpill goes on the list the drag starts in. Without it a mouse drag released outside every list keeps what it did, as in SortableJS. A keyboard, touch or pen drag cancelled with Escape is always put back.
  • While a card is dragged, the columns that take it are outlined, and a column that refuses the position turns red: the script marks the lists with attributes, which cost no render, and the --bit-Sortable-accepts-outline, -over-outline and -refused-outline variables set on the board draw them (see Style & Class).
  • Turn the server's approval off and drag a card into Done: it shows there while the server thinks, then slides back. From the keyboard the same rules apply: carry a card toward Done and the refusal is announced ("Plan the launch cannot be moved there."), and the card stays put.

To do
Write the spec
Draw the icons
Plan the launch
In progress
Build the API
Review the PR
Done (from In progress)
Set up CI
Server: idle

MoveAsync & MoveToAsync

Dragging is not the only way to move an item. MoveAsync moves one within its list and MoveToAsync into another list, named by its Id, as a drag would - the rules apply, ConfirmDrop is asked, the items slide, the events follow with Input set to Api, and the move is announced when it lands. They are the move-up and move-to buttons and item menus that WCAG 2.5.7 (dragging movements) asks an accessible app to offer beside dragging, and that some screen readers in browse mode need. Both return true when the item moved, and refuse while a drag is in progress. A Filter does not stop them, and a multi-drag selection is not carried along.

Backlog
Sign-up page
Password reset
Audit log
Dark mode
Sprint
Search
Export to CSV

Swap

In Swap mode the dragged item trades places with the item it is dropped on, and nothing moves meanwhile: the item under the pointer is highlighted instead (the SwapTarget part), and an item dragged back over itself highlights nothing and changes nothing. The events of a swap say so with IsSwap, and SwappedWith names the other item, so that a handler can save both moves. This mirrors the SortableJS Swap plugin.
  • Between lists, an item dropped onto an item of the other list trades places with it, and each list keeps its length. Each list must be able to take the other's item: the same group, a Pull that lets the item go, and a Put that lets it in. A full list (MaxItems) never refuses a swap for room, and a Clone source gives its item itself away in a swap rather than a copy.
  • From the keyboard, the arrows of a picked-up item move the highlight instead of the item, announced as "Item 1 will trade places with Item 3.", and Space makes the swap.
  • The highlight is drawn with --bit-Sortable-swap-background and --bit-Sortable-swap-outline-color; Classes.SwapTarget gives it a look of its own.

Item 1
Item 2
Item 3
Item 4
Item 5
Order: Item 1, Item 2, Item 3, Item 4, Item 5
Last swap: nothing yet

Left
Item 1
Item 2
Item 3
Right
Item A
Item B
Item C

MultiDrag

With MultiDrag, a click selects an item and another click deselects it, and Shift+click selects a range; dragging any selected item carries the whole selection, which keeps its order and lands as one block where it is dropped. @bind-SelectedItems keeps the selection and a field of the page in step, both ways. Both lists of the second pair share a group, so a selection made in one is dragged into the other. This mirrors the SortableJS multi-drag demo.
  • The selection is spent by the move, and OnEnd's Items lists every item the drag carried. Dragging an item that is not selected clears the selection, and only that item moves.
  • From the keyboard, Shift+Space selects or deselects the focused item, announced as "Item 2 selected. 1 item selected."; Space on a selected item picks the whole selection up, and the arrows move it.
  • SelectedItemsChanged reports the selection, in list order, whenever it changes - a click, a range, Shift+Space, a drag that spends it or one that clears it. A selection the page sets leaves out the items that are not in the list and those a Filter locks; items that leave the list, or are replaced with the whole Items list, leave the selection too.
  • The selected items wear the Selected part, drawn with --bit-Sortable-selected-background and --bit-Sortable-selected-ring-color, and the picture a multi-drag carries shows how many items it moves (--bit-Sortable-count-background, --bit-Sortable-count-color).
  • With a Clone pull, dragging into another list clones only the dragged item. A move made by code (MoveAsync) moves one item and does not carry the selection along.

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Selected: nothing

Left
Item 1
Item 2
Item 3
Item 4
Right
Item A
Item B

Events

A drag raises OnStart on the list it starts in, OnChange each time the item takes a new position, OnUpdate when a list's own order changed, OnRemove and OnAdd when an item crossed from one list into another, OnSort on every list it changed, and OnEnd on the source list, whatever happened. Each comes with a BitSortableEventArgs. The newest event is on top of the log.
  • The completion events are raised after the bound lists have changed and ItemsChanged has been raised, so a handler sees the final state. Within a list: OnUpdate, OnSort, OnEnd. Across lists: OnRemove on the source (not for a clone), OnAdd on the destination, OnSort on the source (not for a clone) and on the destination, then OnEnd. A drag that changed nothing, or was cancelled, raises OnEnd alone, with Canceled set when it was put back.
  • They are all raised once the drag is over, so a handler that takes its time - a save to a server, say - never holds up the next drag.
  • Try it: drag Item 1 below Item 3 (OnStart, then OnUpdate, OnSort and OnEnd); drag Item 4 into the right list (OnRemove on the left, OnAdd on the right, OnSort on both, OnEnd on the left); drag an item into the other list and back home before dropping it (OnStart and OnEnd only); pick an item up with Space, move it and press Escape (OnEnd alone, keyboard and canceled).

events-left
Item 1
Item 2
Item 3
Item 4
events-right
Item A
Item B
No events yet.

Keyboard & Strings

With Keyboard on (the default) a list is one tab stop: the arrow keys move between its items, Space or Enter picks the focused one up, the arrows move it - into the next list of the group too - Home and End to the ends, Space or Enter drops it and Escape puts it back. Every step is announced, naming the item by ItemLabel and the list by its AriaLabel. Strings rewords or translates what is announced.
  • Tab enters the list at the item focused last; during a keyboard drag it drops the item where it is, and moves on.
  • The arrow keys move the focus to the item in that direction; during a drag they move the item to the next place that way and, past the end of its list, into the nearest list of the group in that direction (here, the right arrow from the Backlog carries an item into the Sprint).
  • Home and End focus the first and the last item; during a drag they move the item to the start or the end of its list.
  • Space or Enter picks the focused item up, and drops it. Escape puts it back where it was.
  • Shift+Space selects or deselects the focused item of a MultiDrag list.
  • The arrows follow the layout - up and down a vertical list, along a row, right to left in a right-to-left one, row to row in a grid, from column to column of a board, into a nested list - because the next item, or list, is looked for in the direction of the key.
  • A keyboard drag moves the item itself, into another list too, and the focus follows it. Every rule applies as for a pointer: a refused position, a full list or a list of another group is announced as refused, ConfirmDrop is asked on the drop, and in Swap mode the arrows move the highlight.
  • Keys pressed inside an item - on a button, in an input - are left to it: only an item itself, or its drag handle, answers them. Keyboard="false" turns it all off, and a Disabled list is not focusable.
  • A list is a list of listitems, each described as a "sortable item" (RoleDescription) and pointing to the keyboard instructions (Instructions, through aria-describedby), and named by AriaLabel. Each step is announced through a live region with the item's name, its position and the list it is in; a pointer drag is announced when it starts and when it ends. A drag is announced in the Strings of the list it started in. The texts are functions of a BitSortableAnnouncement, and can be set for every list at once through a BitSortableParams.
  • The focus outline of an item, and the dashed one of an item picked up, are drawn in forced colors (Windows high contrast) too.

Backlog
#1 Sign-up page
#2 Password reset
#3 Audit log
Sprint
#4 Search
#5 Export to CSV

Touch & pen

A finger drags an item after resting on it for TouchDelay milliseconds, so a swipe over the list still scrolls the page; Delay is the same wait for the mouse and the pen. A pointer that moves more than DelayTolerance pixels first is a scroll or a click instead. With ForceFallback the mouse drags the way a finger does, with a preview of the item that follows it, instead of the browser's own drag image.
  • A mouse drags with the browser's own HTML5 drag and drop, as SortableJS does on the desktop. A finger or a pen drags with pointer events, which work the same in every browser and web view, whether or not it supports HTML5 drag and drop on touch: the item stays in its list, dimmed, while a copy of it follows the pointer. Both feed the same hit test and raise the same events, with Input saying which it was. ForceFallback is also for a web view whose native drag and drop does not work.
  • Once a finger drags an item the page does not scroll under it; near an edge, the drag scrolls the list, a panel around it or the page (see Large list).
  • Escape, a system gesture that takes the pointer over, or leaving the page cancels a pointer drag and puts everything back. The click a browser sends after a press is swallowed after a drag, so dropping an item does not also click it, and a press on a control inside an item - a button, a link, an input - is left to the control.
  • The preview is a copy of the item placed above the page, in the Drag part: --bit-Sortable-drag-opacity and --bit-Sortable-drag-shadow restyle it, set on :root since the preview is outside the list.
  • In the second list a finger on the grip drags at once: the handle has touch-action: none, so the browser does not scroll from it, and TouchDelay is 0. The rest of the row still scrolls the page.

Long press
Kale
Lemons
Milk
Nuts
Oats
Handle, at once
Dishes
Laundry
Plants
Recycling

Large list

Three hundred rows in a scrolling panel. Drag a row toward the panel's edge and it scrolls: the browser scrolls for the mouse's own drag, the list for a finger, a pen or a ForceFallback mouse - when Scroll is on, within ScrollSensitivity pixels of the edge and at up to ScrollSpeed pixels a frame, faster the closer the pointer is to the edge. IsolateItems renders each row's template in a component of its own, which a step of the drag does not render again.
  • The pointer is followed and measured in the browser: a step that does not change the drop position never reaches .NET, and one that does is a single call - while it is on its way the browser keeps the latest position for when it returns, so no position is lost and none queues up. That keeps a drag smooth on Blazor Server too.
  • A new position changes the bound list in place and renders the list once, and the browser slides the rows when that render lands. A render of the list renders all its items' templates; with IsolateItems only the wrappers move. Leave it off when a template shows something that other items' moves change, such as the item's position number: that would only catch up when the drag ends.
  • From the keyboard, pick Row 1 up and hold the down arrow: the row walks down, and the panel follows it into view.
  • In the browser's console, BitBlazorUI.Sortable.diagnostics() after a drag shows the positions sent to .NET - one per row crossed, not one per pointer move - and the average and slowest round trip; BitBlazorUI.Sortable.resetDiagnostics() starts over.
  • A list renders every item it is given: Blazor's Virtualize is not supported, since rows that are not rendered could be neither measured nor dropped beside. Page a list that is too long to render, or let a filter narrow it.

Row 1 open
Row 2 in review
Row 3 blocked
Row 4 in review
Row 5 open
Row 6 blocked
Row 7 open
Row 8 in review
Row 9 blocked
Row 10 in review
Row 11 open
Row 12 blocked
Row 13 open
Row 14 in review
Row 15 blocked
Row 16 in review
Row 17 open
Row 18 blocked
Row 19 open
Row 20 in review
Row 21 blocked
Row 22 in review
Row 23 open
Row 24 blocked
Row 25 open
Row 26 in review
Row 27 blocked
Row 28 in review
Row 29 open
Row 30 blocked
Row 31 open
Row 32 in review
Row 33 blocked
Row 34 in review
Row 35 open
Row 36 blocked
Row 37 open
Row 38 in review
Row 39 blocked
Row 40 in review
Row 41 open
Row 42 blocked
Row 43 open
Row 44 in review
Row 45 blocked
Row 46 in review
Row 47 open
Row 48 blocked
Row 49 open
Row 50 in review
Row 51 blocked
Row 52 in review
Row 53 open
Row 54 blocked
Row 55 open
Row 56 in review
Row 57 blocked
Row 58 in review
Row 59 open
Row 60 blocked
Row 61 open
Row 62 in review
Row 63 blocked
Row 64 in review
Row 65 open
Row 66 blocked
Row 67 open
Row 68 in review
Row 69 blocked
Row 70 in review
Row 71 open
Row 72 blocked
Row 73 open
Row 74 in review
Row 75 blocked
Row 76 in review
Row 77 open
Row 78 blocked
Row 79 open
Row 80 in review
Row 81 blocked
Row 82 in review
Row 83 open
Row 84 blocked
Row 85 open
Row 86 in review
Row 87 blocked
Row 88 in review
Row 89 open
Row 90 blocked
Row 91 open
Row 92 in review
Row 93 blocked
Row 94 in review
Row 95 open
Row 96 blocked
Row 97 open
Row 98 in review
Row 99 blocked
Row 100 in review
Row 101 open
Row 102 blocked
Row 103 open
Row 104 in review
Row 105 blocked
Row 106 in review
Row 107 open
Row 108 blocked
Row 109 open
Row 110 in review
Row 111 blocked
Row 112 in review
Row 113 open
Row 114 blocked
Row 115 open
Row 116 in review
Row 117 blocked
Row 118 in review
Row 119 open
Row 120 blocked
Row 121 open
Row 122 in review
Row 123 blocked
Row 124 in review
Row 125 open
Row 126 blocked
Row 127 open
Row 128 in review
Row 129 blocked
Row 130 in review
Row 131 open
Row 132 blocked
Row 133 open
Row 134 in review
Row 135 blocked
Row 136 in review
Row 137 open
Row 138 blocked
Row 139 open
Row 140 in review
Row 141 blocked
Row 142 in review
Row 143 open
Row 144 blocked
Row 145 open
Row 146 in review
Row 147 blocked
Row 148 in review
Row 149 open
Row 150 blocked
Row 151 open
Row 152 in review
Row 153 blocked
Row 154 in review
Row 155 open
Row 156 blocked
Row 157 open
Row 158 in review
Row 159 blocked
Row 160 in review
Row 161 open
Row 162 blocked
Row 163 open
Row 164 in review
Row 165 blocked
Row 166 in review
Row 167 open
Row 168 blocked
Row 169 open
Row 170 in review
Row 171 blocked
Row 172 in review
Row 173 open
Row 174 blocked
Row 175 open
Row 176 in review
Row 177 blocked
Row 178 in review
Row 179 open
Row 180 blocked
Row 181 open
Row 182 in review
Row 183 blocked
Row 184 in review
Row 185 open
Row 186 blocked
Row 187 open
Row 188 in review
Row 189 blocked
Row 190 in review
Row 191 open
Row 192 blocked
Row 193 open
Row 194 in review
Row 195 blocked
Row 196 in review
Row 197 open
Row 198 blocked
Row 199 open
Row 200 in review
Row 201 blocked
Row 202 in review
Row 203 open
Row 204 blocked
Row 205 open
Row 206 in review
Row 207 blocked
Row 208 in review
Row 209 open
Row 210 blocked
Row 211 open
Row 212 in review
Row 213 blocked
Row 214 in review
Row 215 open
Row 216 blocked
Row 217 open
Row 218 in review
Row 219 blocked
Row 220 in review
Row 221 open
Row 222 blocked
Row 223 open
Row 224 in review
Row 225 blocked
Row 226 in review
Row 227 open
Row 228 blocked
Row 229 open
Row 230 in review
Row 231 blocked
Row 232 in review
Row 233 open
Row 234 blocked
Row 235 open
Row 236 in review
Row 237 blocked
Row 238 in review
Row 239 open
Row 240 blocked
Row 241 open
Row 242 in review
Row 243 blocked
Row 244 in review
Row 245 open
Row 246 blocked
Row 247 open
Row 248 in review
Row 249 blocked
Row 250 in review
Row 251 open
Row 252 blocked
Row 253 open
Row 254 in review
Row 255 blocked
Row 256 in review
Row 257 open
Row 258 blocked
Row 259 open
Row 260 in review
Row 261 blocked
Row 262 in review
Row 263 open
Row 264 blocked
Row 265 open
Row 266 in review
Row 267 blocked
Row 268 in review
Row 269 open
Row 270 blocked
Row 271 open
Row 272 in review
Row 273 blocked
Row 274 in review
Row 275 open
Row 276 blocked
Row 277 open
Row 278 in review
Row 279 blocked
Row 280 in review
Row 281 open
Row 282 blocked
Row 283 open
Row 284 in review
Row 285 blocked
Row 286 in review
Row 287 open
Row 288 blocked
Row 289 open
Row 290 in review
Row 291 blocked
Row 292 in review
Row 293 open
Row 294 blocked
Row 295 open
Row 296 in review
Row 297 blocked
Row 298 in review
Row 299 open
Row 300 blocked

ItemKey

ItemKey says what identifies an item - its id - for rows that a server sends again as new objects. Select two rows and load them again: with ItemKey they keep their elements, their focus and their selection, and a drag moves the object the list holds now; without it, the new objects are new items to the list, and the selection is gone. The key must be unique within the list and stay the same while the row is in it. It is also how the list spots a duplicate: a row whose key is already in a list is never dropped into it, so a Clone factory gives a copy a key of its own. A lambda written inline is fine: the list tells a new ItemKey by its code, not by the delegate a render creates.

Write the spec
Review the design
Build the API
Ship it
Loaded 1 time(s)

Cascading parameters

BitParams with a BitSortableParams sets the defaults of every sortable list inside it - put one around the app's router for app-wide defaults; a parameter of the list itself still wins (the second list has an EmptyText of its own). It carries Animation, Classes, Delay, DelayTolerance, EmptyText, ForceFallback, Keyboard, RevertOnSpill, Scroll, ScrollSensitivity, ScrollSpeed, Strings (the announcements in the app's language), Styles, SwapThreshold and TouchDelay (a longer long press), besides the parameters every component takes.

One
Two
Three
My own empty text.

Style & Class

Style and Class reach the root of the list, Styles and Classes its parts - the items, the drag states and the empty state - and ItemStyle gives each item an inline style of its own, the way ItemClass gives it a class. The drag states read the public --bit-Sortable-* variables, which inherit: set them on :root, on an ancestor, or on the Style of a list. The last two lists set the ghost, the picked-up item and outlines for the lists that take the drag.
  • Root: the list (bit-srt), with bit-dis while Disabled and bit-srt-hnd with a Handle.
  • Item: every item wrapper, and the drop placeholder.
  • Ghost: the item being dragged with a pointer, in its list, and the drop placeholder in another list.
  • Chosen: the item picked up - also from the keyboard, which wears only this one.
  • Drag: the preview that follows a finger, a pen or a ForceFallback mouse, placed above the page.
  • SwapTarget, Selected and Filtered: the swap target, the items of a multi-drag selection, and the items a Filter locks.
  • Empty: what an empty list shows.
  • While a drag runs the script also sets attributes to style, at no render cost: data-bit-srt-accepts on every list that takes the drag, data-bit-srt-over on the one under the pointer, data-bit-srt-refused on that one when it refused the position, and data-bit-srt-dragging on the html element, set to native, pointer or keyboard.
  • The stylesheet draws only these states, and leaves the look of the list and its items to the page.

Style & Class
Styled 1
Styled 2
Styled 3
Styles & Classes
Classy 1
Classy 2
Classy 3
ItemStyle
Ordinary
Important
Routine

Apple
Banana
Cherry
Fig
Grape

RTL

Use BitSortable in right-to-left (RTL). The list is measured in its own order, so dragging an item toward the left moves it forward - drag the first step to the far left and it becomes the last - and from the keyboard the left arrow moves it to the next place.

گام ۱
گام ۲
گام ۳
گام ۴
گام ۵
ترتیب: گام ۱، گام ۲، گام ۳، گام ۴، گام ۵

CSS variables

The public custom properties this component reads off its root, for what no parameter covers.

Every variable is read with a fallback and never declared by the component, so it inherits like any other custom property: set one on :root (or in a [bit-theme] block) to restyle every instance, on any ancestor to restyle the ones inside it, or on the Style of one instance to restyle it - and any instance nested inside it, which inherits the value too; a parameter changes one alone, as does the real CSS property on the instance's Style / Styles when that property does not inherit (opacity: 1 keeps one disabled instance undimmed without undimming a disabled one inside it), while an inherited one such as color or font-family also reaches the nested instances that do not set it themselves. Leave a variable unset and the component falls back to the theme token beside it.

BitSortable CSS variables

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.

API

Every parameter, public member, sub-class and enum this component exposes.

BitSortable 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.

BitSortable 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.

BitComponentBase parameters

Name Type Default value Description
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.

BitComponentBase public members

Name Type Default value Description
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.

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.

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.

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.