Skip to content

Simple list

Drag the items to reorder them. The list reorders live as you drag, the other items slide out of the way, and your own IList<string> is changed in place through @bind-Items - the order under the list is read straight from it.

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6

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

Try it

  • Drag Item 1 down past Item 3. It moves in the list as soon as the pointer enters the next item, the others slide out of its way, and Order changes when you drop it.
  • Move the Animation slider to 1000 to watch the slide in slow motion, or to 0 to turn it off. A move that starts while a slide is still running picks it up from where the item is, so nothing jumps.
  • Without a mouse: Tab into the list, pick the focused item up with Space, move it with ↑ ↓, and drop it with Space - or put it back with Escape. See keyboard and screen readers.
  • 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 and pen.

How it works

  • Every item is wrapped in a <div> that carries the drag handlers; ItemTemplate renders what goes inside it.
  • The wrappers are rendered with @key, so when the item moves in your list Blazor moves its existing DOM node instead of recreating it - which keeps the browser's drag alive while the list reorders under it. That is also why the items of a list must be unique: a list of strings must not hold the same string twice.
  • The bound list must be mutable - a List<T>, or anything else whose IsReadOnly is false. Declare the field as IList<TItem>, the parameter's own type, or @bind-Items does not compile.
  • 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.
  • Before each change the list records where every item is, lets Blazor update the DOM, then slides each item from its old place to its new one (the FLIP technique). With the system's reduced-motion setting on, nothing slides.

Parameters on this page

ParameterHereWhat it does
@bind-Items_itemsThe items to show and reorder. The list is changed in place, and ItemsChanged tells your field.
TItemstringThe item type. Any type works; the items are passed to ItemTemplate and to every event, typed.
ItemTemplate@itemWhat each item shows, inside its wrapper.
Idsimple-listThe list's DOM id, and the FromId / ToId its events report. Generated when not set.
Class, ItemClassdemo-list, demo-itemThe CSS classes of the list container and of every item wrapper. The look of the list is yours.
GhostClassdemo-ghostReplaces bit-bortable-ghost, the class of the item being dragged: a dashed card here, instead of the stylesheet's dimmed one.
Animationthe sliderHow long, in milliseconds, items take to slide into place; 150 by default, 0 turns it off.
An unhandled error has occurred. Reload 🗙