Extras
Sortable
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
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
- 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).
Animation
Group
- 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.
EmptyText & EmptyTemplate
Clone
- 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.
Sort, Put & Pull
- 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.
Disabled
Handle
- 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.
Filter
- 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.
Swap thresholds
- 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.
Grid & horizontal lists
- 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.
Nested lists
- 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.
PutGroups
MaxItems & MinItems
CanDrop, ConfirmDrop & RevertOnSpill
- 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.
MoveAsync & MoveToAsync
Swap
- 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.
MultiDrag
- 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.
Events
- 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).
Keyboard & Strings
- 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.
Touch & pen
- 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.
Large list
- 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.
ItemKey
Cascading parameters
Style & Class
- 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.
RTL
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.