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.

Swap, multi-drag & events

Moving items from code, swap mode, dragging several selected items at once, and the events every drag raises.

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.

Feedback

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