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.

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.