Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Structure

SortableList

A list people put in order, by dragging a row's handle or with the keyboard.

Arow per item with ahandle

When to useLink to "When to use"

  • Ordering a short list: sidebar sections, favourites, steps, priorities.

Use something else when:

  • the order comes from data (date, name): sort it, and let people pick the sort
  • the list is long: offer "Move to top" or position fields as well; dragging far is hard for everyone

UsageLink to "Usage"

tsx
Copy
import { SortableList } from "@arshad-shah/cynosure";

<SortableList label="Sidebar order" items={sections} onReorder={setSections} />

Each item has an id, a plain-text label (used in announcements and the handle's name) and optional content to show instead.

KeyboardLink to "Keyboard"

Focus a handle, press Space (or Enter) to pick the row up, move it with the arrow keys, and press Space again to drop it. Escape puts it back.

Keyboard picks up moves and drops

GridsLink to "Grids"

layout="grid" wraps the items into as many columns as fit (--cy-sortable-list-tile-min sets the smallest tile), for file grids and page thumbnails. Dragging works across rows; with the keyboard, Left and Right move a tile one place (following the reading direction) and Up and Down move it a whole row.

Agrid of tiles

PropsLink to "Props"

Every prop of SortableList
PropWhat it doesTypeDefault
labelRequired
Accessible name of the list.string
items
Controlled items, in order: { id, label, content? }.SortableItem[]
defaultItems
Starting items when uncontrolled.SortableItem[]
onReorder
Called with the items in their new order after a move is dropped.((items: SortableItem[]) => void)
disabled
Disables the handles, so nothing can be moved.boolean
layout
list (rows, default) or grid (tiles that wrap: file grids, page thumbnails)."list" | "grid"
size
Text size of the rows. Default "md".Size"md"
labels
Replace the built-in English text: the handle name, the instructions and the announcements.Partial<SortableListLabels>
className
Added to the root element, for layout.string
style
Layout only. Restyle through --cy-sortable-list-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

  • Handles: each row's handle is a button named "Move …" and described by the instructions. While its row is moving it is aria-pressed.
  • Keyboard:
Behaviour and accessibility, table 1
KeyAction
Space / EnterPick up the row; again to drop it
Arrow Up / DownMove the row one place
Home / EndMove the row to the top / bottom
EscapeCancel: the row goes back where it was
TabDrop the row where it is and move on
  • Announcements: "Docs picked up. Position 2 of 4.", "moved to position 3 of 4", "dropped at…" and "Move cancelled…" are announced politely (all in labels).
  • Pointer and touch: drag a handle; the other rows slide out of the way (detent, animated unless motion is reduced) and a long list scrolls near its edges. Touch dragging does not scroll the page; handles have a 44px hit area on touch screens.
  • Changes: onReorder is called once, on drop, and only if the order changed.

ThemingLink to "Theming"

Tokens: --cy-sortable-list-item-background and --cy-sortable-list-radius.

Tree · Steps

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog