Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

List for Vue

Grouped rows people reorder by mouse, touch or keyboard, across groups too. A sortable list for Vue and Ark UI where a board won't fit.

On this page9 sections
UI library: Ark UI

A list stacks rows in groups, one group under another, and people reorder them by dragging a row up or down or with the keyboard, from one group into the next. It suits a support queue by priority, a roadmap split into Now, Next and Later, or tasks by status in a side panel. The pointer and key handling is the list's own code, with no drag-and-drop package.

When the stages should sit side by side, use a Kanban board. Rows people sort by a column belong in a Table.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

List anatomy: provider, group, header, items, item

Usage

import { useState } from "react";
import {
  ListGroup, ListHeader, ListItem, ListItems, ListProvider,
} from "@/components/ui/list";
const statuses = [
  { color: "var(--muted-foreground)", id: "todo", name: "To Do" },
  { color: "var(--primary)", id: "done", name: "Done" },
];

const Tasks = () => {
  const [tasks, setTasks] = useState([
    { id: "1", name: "Research competitors", status: "todo" },
    { id: "2", name: "Set up the project", status: "done" },
  ]);

  return (
    <ListProvider onValueChange={setTasks} value={tasks}>
      {statuses.map((status) => (
        <ListGroup id={status.id} key={status.id}>
          <ListHeader color={status.color} name={status.name} />
          <ListItems>
            {tasks
              .filter((task) => task.status === status.id)
              .map((task) => (
                <ListItem id={task.id} key={task.id} name={task.name} />
              ))}
          </ListItems>
        </ListGroup>
      ))}
    </ListProvider>
  );
};

The items are one flat array. Each has an id, a name and the status of the group it sits in, and their order in the array is their order within each group. A move hands the whole new array to onValueChange, and the list shows only what value holds.

Accessibility

Each row is a tab stop with the button role, described as a draggable item, and its aria-describedby points at a hidden line explaining the keys. A row lifted from the keyboard reports aria-pressed as true and drops where it is once focus leaves it, by Tab or a click. Each group is a group labeled by its header. A polite live region announces each pick-up, step, drop and cancel, such as "Dropped Search ignores accents in Closed, position 2 of 2", and calls the group by the header's name. What stays with you: a header with a name in every group, a name on every item that reads well aloud, and a translation of the English sentences in components/ui/list.

Space
On a row, picks it up. On a row you are holding, drops it where it is.
Enter
On a row, picks it up. On a row you are holding, drops it where it is.
Arrow Up
Moves the held row up one place. From the top of a group, moves it to the end of the group above.
Arrow Down
Moves the held row down one place. From the end of a group, moves it to the top of the group below.
Home
Moves the held row to the top of its group.
End
Moves the held row to the end of its group.
Escape
Cancels the move and puts the row back where it was picked up, during a mouse drag as well.
Tab
Drops the held row where it is and moves focus on. With no row held, moves focus as usual.

Demos

Single group

Five books under one Reading list header, every item sharing the same status, so the rows only move up and down and Home and End reach the top and the bottom. Each row's number follows its place, since it comes from the array's order. Reach for this when people rank one queue, a reading list or a playlist, with no stages to sort into.

Preview width

Custom items

A support queue under Urgent, This week and Later, where each row has a grip icon, the ticket's title, an outline Badge for its kind and the owner's avatar, and each header ends in a count. ListItem renders its children in place of its name, and ListHeader its children in place of the dot, while its name still names the group aloud. The grip is only a hint.

Preview width

Move events

Three issues under Open and Closed, with a line under the list that prints what @move-start and @move-end report: the row, the group and position it came from, and where it went to, or that it went back when the move was cancelled. Both fire for a drag and for the keyboard. Save or log a move from the end event, which fires once when the move is over.

Preview width

Scrolling

Ten roadmap items under Now, Next and Later, in a list given h-80 and overflow-y-auto so it scrolls inside its own frame. Drag a row near the frame's top or bottom edge and the list scrolls under it. Pick this when the list shares a panel with other content, since a list without a height grows the page and the same drag scrolls the window instead.

Preview width

FAQ

What data does the List need?

One array, value, with every item's own id, a name and the status it sits under. Each ListGroup takes the id of one status, and inside it you render that status's rows.

There is no index field: a row's position in its group is its order in the array, so filter the array for each group without sorting it. Items can carry fields of their own, such as an owner or a label, and a move keeps them while it changes status and the order.

How do I save a List's new order in Vue?

Save from @move-end, which fires once per finished move with the row's id, where it came from and where it went to, each a status and a 0-based index. When the move is cancelled, or the row is dropped outside the list, to is null. Keep @value-change for your state: it fires on every arrow-key step and again when Escape restores the list, so sending it to a server would save moves nobody finished.

The list keeps no copy of the items. If a dropped row jumps back, the new array isn't reaching value. The Move events demo prints both events.

Can people reorder the List from the keyboard?

Yes. Tab to a row and press Space or Enter to pick it up, then move it with the up and down arrows. Past the end of a group it carries on into the next one, and Home and End send it to the top or bottom of its group.

Press Space or Enter to drop it, or Escape to put it back where it started. A live region announces each step with the group and the position, as the Accessibility section describes.

Can I reorder the List on a phone?

Yes. A finger held still on a row for a quarter of a second picks it up, and from then on the page stays put while the row follows the finger up or down.

A finger that moves before then is treated as a scroll, so swiping through a long list still works. A dragged row moves only up and down, keeping its width and its place across, so a finger that drifts sideways doesn't lose the drop.

How do I make a long List scroll inside a panel?

Give ListProvider a height and overflow-y-auto, as the Scrolling demo does with h-80. Dragging a row near the top or bottom of that frame scrolls it, faster the closer the pointer gets to the edge.

Without a height the list grows with its rows, and a drag near the top or bottom of the window scrolls the page. Add overscroll-contain beside the height if scrolling past the end of the list shouldn't carry on into the page.

How do I show a count or an action in a List group header?

Pass children to ListHeader. They replace the colored dot and the name, as in the Custom items demo, which adds a count. Without children, color takes any CSS color for the dot, so var(--primary) follows the theme.

Give ListHeader a name beside the children, as the demo does, since the announcements call the group by it, so a row is picked up from "Urgent", not from "Urgent2". Without name they read the header's whole text, count and all.

A button in the header, such as Add task, works as usual, since only rows start a drag. The group's own label is the header, so a screen reader still hears the count and the button's label on entering the group.

Can I use the List as a plain sortable list without groups?

Yes. Give every item the same status and render one ListGroup with that id, as the Single group demo does. Rows then move up and down within it, and Home and End reach the top and the bottom.

Keep a ListHeader even then, with a name such as "Reading list", because it labels the group and the announcements use it. Without a header, they fall back to the status id, so a row would be announced as being in "all" or "default".

Should I use List or Kanban?

Use List in a narrow space, or when the groups read best one under another, such as priorities from most to least urgent. Use Kanban when the stages sit side by side and people move work across them.

Both take a flat array of items and move them the same way, by pointer, touch or keyboard. The item's group field is status on a List and column on a Kanban board.

API Reference

ListProvider

PropType
valueT[]

The items, in order. Render each group's rows from it.

class?string

Merged with the part's classes.

EventType
@value-change(value: T[]) → void

Called with every item, in order, after each move. Set value from it.

Parameters

value – T[]

Returns
void
@move-end(details: ListMoveDetails) → void

Called when an item is dropped, or its move is cancelled (to is null).

Type
(details: ListMoveDetails) → void
Parameters

details – { from: ListSpot; id: string; to: ListSpot | null }

Returns
void
@move-start(details: ListMoveDetails) → void

Called when an item is picked up, by the pointer or the keyboard.

Type
(details: ListMoveDetails) → void
Parameters

details – { from: ListSpot; id: string; to: ListSpot | null }

Returns
void

ListGroup

PropType
idstring

The id of the status this group holds: items with that status.

class?string

Merged with the part's classes.

ListHeader

<div> data-slot="list-header"

PropType
color?string

The status's color: a dot before the name. Any CSS color, a theme variable included.

name?string

The status's name: what announcements call the group, and the header's text when it has no children. Without it, announcements read the header's whole text, children and all.

class?string

Merged with the part's classes.

AttributeType
data-list-name?string

Mirrors name.

ListItems

<div> data-slot="list-items"

PropType
class?string

Merged with the part's classes.

ListItem

data-slot="list-item"

PropType
idstring

The item's id.

namestring

The item's name: the row's content when it has no children.

class?string

Merged with the part's classes.

AttributeType
data-drop?string
data-held?string

Present when held is true.

data-lifted?string
data-list-item?string

Mirrors id.