Sortable List

View as Markdown

Rows you put in order by dragging a grip or with the arrow keys, read out as they move.

  1. SAML single sign-onPlatform13 pts
  2. Usage-based billingBilling21 pts
  3. Offline mode on mobileMobile8 pts
  4. Audit log exportPlatform5 pts
  5. Summaries in the inboxAI8 pts

When to use

Rows you put in order by dragging a grip or with the arrow keys, read out as they move. Use Board instead when the rows move between stages, not just up and down.

Usage

import { SortableList } from "./ui/uicontext/components/SortableList.ts"
const Message = UiSchema.TaggedEnum({ Reordered: { from: Schema.Number, to: Schema.Number } })export const Steps = (h: Html.H<typeof Message.Type>, steps: ReadonlyArray<{ readonly id: string; readonly title: string }>) =>	SortableList(h, { label: "Onboarding steps", items: steps.map((s) => ({ id: s.id, label: s.title })), onReorder: (from, to) => Message.Reordered({ from, to }) })

Examples

A dashboard's cards

meta holds anything at the row's end. Without numbered the rows carry no rank.

  1. Revenue this monthShown
  2. New signupsShown
  3. Churn riskHidden
  4. Open ticketsShown

API reference

Options

SortableList options
NameTypeDescription
keystringNames the list among others in the same view; needed for more than one.
labelrequiredstringWhat the list holds: "Priorities".
itemsrequiredSortableItem<Message>[]—
onReorderrequired(from: number, to: number) => Message—
numberedbooleanNumbers the rows 1, 2, 3, for a ranking.
disabledboolean—
styleStyle—

Keyboard and accessibility

KeysDoes
Space EnterOn a grip, pick the row up, then drop it
Up arrow Down arrowMove the picked-up row
Home EndMove it to the top or the bottom
EscapePut it back where it was

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/sortable-list

Source