Reorder list
ProA vertical list whose rows a person puts in order: by dragging a handle, with the arrow keys, or from a move menu with no drag at all, each move said to screen readers. Not an M3 component (@windmorph/react-pro).
import { ReorderList, ReorderListItem, useReorderListItem } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Purpose
A vertical list whose rows a person puts in order, for any list whose order is the content: episodes, recipe steps, a playlist, a profile's links, a table's columns. Each row holds your own content beside a handle.
M3 defines a list item's dragged look, which this list takes; the drag itself runs on the core's useReorder engine (in @windmorph/react/primitives). The core List reorders its own list items too, with onReorder; use this one for rows of your own content, and a MediaUploadGrid to order photos being uploaded. Moving a row to another list stays a menu item of your own.
Moving a row
- Dragging the handle with a mouse, a finger or a pen: past 4px the row lifts in M3's dragged look (
tertiary-container, level 4 elevation, 16px corners) and follows the pointer along the list; the rows it passes slide out of its way, and where it will land shows as the drop zone. Near the edge of a scrolling parent, or the window, the list scrolls. Escape, a cancelled pointer, the window losing focus, or the items changing put the row back. - The keys on the focused handle: Up and Down move the row one place, Home and End to the top and bottom, at once.
- The move menu: a press on the handle that doesn't drag opens Move up, Move down, Move to top and Move to bottom, so nothing needs a drag (WCAG 2.5.7). A row with a menu of its own turns it off with
moveMenu={false}and moves throughuseReorderListItem()inside the row (moveUp,moveDown,moveToTop,moveToBottom,canMoveUp,canMoveDown); give every row such a menu then, or keyboard and screen-reader users have no way to move it (a development warning says so when no row uses the hook).
Behaviour
- The order is yours (controlled only):
onReorder(keys, move)is called once a move lands, with every key in the new order and the{ key, from, to }of the move. Keys come back as strings, as React keeps them (a key7is"7"). Give the old order back to refuse it, and the row slides back. - A key repeated across arrays or fragments still works: each row keeps its own place and
onReordergives back the keys as written, while a development warning names the repeated key so the app can make it unique. - Focus stays with the moved row's handle (or your own control in it) and the row stays in view. A row that leaves while focus is in it hands focus to the row that took its place, else the one before, else the list.
- A row with
reorderable={false}has no handle, keeps its column, and keeps its place: no row moves past it. A list of one row has no handle either.disabledkeeps the handles, disabled, so nothing shifts while you save. handlePlacement="end"puts the handle at the row's end. The lifted row carriesdata-dragged, a row just dropped or put backdata-droppedfor its first frame in place (the lifted look it fades from: style it as you styledata-dragged), and rows of a disabled listdata-disabled.
When not to use
For rows that are picked rather than ordered, use a List; to order photos being uploaded, the Media upload grid.
See also
- List: Rows with headline, overline, supporting text and leading or trailing content (icons, avatars, images, video thumbnails); items can be links, switches, checkboxes or radio buttons, and put in order by drag or a menu.
- Media upload grid: The photos someone is adding: upload progress and errors, remove and retry, drag to reorder (mouse, touch or keyboard), an add tile and file drop. Not an M3 component (@windmorph/react-pro).
- Menu: A temporary list of choices anchored to a trigger, with groups, selection, submenus and context menus, or a bottom sheet on phones.