An open source design system that's fully customizable and agent ready
schema_version: 4 template_version: 2 kind: system-spec id: spec:AST-103 authority: current archive_reason: null superseded_by: null approved_by: cixzhang approved_at: 2026-10-25 phase: accepted owners: [cixzhang] affects_architecture: [architecture:public-component-api] affects_families: [] affects_contributing: [] affects_consumer_docs: []
Reorderable collections system spec
{
"paths": ["packages/core/src/**", "packages/lab/src/**"]
}
Intent
createReorderable applies to a whole collection: its object is passed as
the collection's reorderable prop, or attached to a container of plain
elements (FR4b). Per-item control comes from each item's
key (itemKey, or the collection's existing identity) and from
isReorderable(key).
A person can change the order of items in a collection by dragging a row's
handle, by keyboard, or with a screen reader, and every collection that allows
it behaves the same way. A caller turns reordering on by passing one
behavior object, made once by createReorderable, to the collection's
reorderable prop or attaching it to plain elements, and applies the change
it reports. A collection that does
not reorder loads none of it.
Non-goals
- Moving several items in one drag, a destination predicate, moves between collection instances; each can be added later without changing this contract.
- Moving items between collections, freeform canvas placement, and file drops.
- Reorder motion values, thresholds, and timing: these stay internal
(
spec:AST-002FR3) and come from the theme's motion roles andspec:AST-094's measured values. - The visual treatment of a moving row and the insertion cue, which
design:ordered-collection-reorderingowns.
Public contract
import {createReorderable} from '@astryxdesign/core';
const moveTo = (items, key, to) => {
const moved = items.find(item => item.id === key);
const rest = items.filter(item => item.id !== key);
return [...rest.slice(0, to), moved, ...rest.slice(to)];
};
const reorderable = useMemo(
() =>
createReorderable({
onReorder: ({key, to}) => setItems(items => moveTo(items, key, to)),
}),
[],
);
<Button label="Move" onClick={() => reorderable.start(selectedId)} />
<List reorderable={reorderable}>
{items.map(item => (
<ListItem key={item.id} itemKey={item.id} label={item.name} />
))}
</List>;
A second collection uses the same object and options, wired to its own internals. A tree reports positions as a parent and an index:
const reorderable = createReorderable({
onReorder: ({key, to}) => setTree(tree => moveNode(tree, key, to)),
});
<TreeList reorderable={reorderable} items={tree} />;
Here to is { parent, index } and keys are the nodes' existing ids; the handle, keys, actions, and
announcements are those of FR3 and FR4, and the tree adds no option.
Without React, the same object attaches to plain elements:
const {detach} = reorderable.attach(listElement, {
items: () =>
cards.map(card => ({key: card.id, element: card.el, handle: card.grip})),
});
Requirements
FR1 — One factory makes the behavior.
createReorderable(options)returns a reorderable object.optionscarries the change callback,onReorder({ key, to }), an optionalisReorderable(key)predicate, and an optionalpositions(), which supplies drop positions for layouts such as a fanned hand or a custom grid; collections the measured layout already places do not need it.positions()returns one{x, y}per item, in item order: the center of that item's slot, in pixels from the top-left corner of the collection's container box. A drag reports astothe slot, within the drop range, whose center is nearest the dragged item's center, and a dropped item settles on that slot's center. An array whose length differs from the item count is ignored, as ispositionsin a tree; drop positions then come from the measured layout. Implementation gap: not built;positionsdoes not exist yet, so drop positions always come from the measured layout. Withoutpositions, drop positions come from the measured layout; in the callback,keynames the moved item by its key andtois the index the item has after the move, counted in the collection's full item order (every item it was given, mounted or not). In a tree,tois{ parent, index }:parentis the new parent's key (nullat the root) andindexis the item's position among that parent's children after the move (DEC-3). It carries no gesture, animation, or timing settings. An optionalisReorderable(key)predicate keeps a row in place: a row it rejects shows no handle and cannot be picked up (DEC-2). A row it rejects at either end of the collection also bounds the drop range: nothing drops beyond it, and a keyboard or assistive-technology move past it is refused and announced (FR4). Each item's key comes from the data, never from React'skey: List reads eachListItem'sitemKey, a string or a number, the shape Table'sidKeyreturns, andonReorderreports that key as given; a collection whose items already carry an identity, such as TreeList'sidor Table'sidKey, uses it; and a data collection without one takesidKeyin Table's shape, a field name or a function of the item (DEC-4). A row without a key shows no handle and cannot be picked up. The object is meant to be created once per collection, for example withuseMemo; one created again on each render still works, because the collection uses the latest callbacks when a move commits and a new object during a drag does not cancel the drag. One object passed to two collections, or attached to two containers, reorders each on its own and moves nothing between them; itsstarttargets the one mounted or attached last, with a development warning. The object carries its machinery under a registered key, so the package and a swizzled copy agree on it (spec:AST-110FR3): a swizzledList,TransferListorListInputreads an object the package made, and the package reads one a copy adapted.optionsalso takeslabels?: ReorderableLabels, which holds every string the object announces or shows (architecture:internationalizationINV3a):- announcements:
pickedUpanddropped(a drag's pick-up and drop, with position and count),cancelled(a cancelled drag, back to its position),place,placeAtTop,placeAtEnd,placeInGrid, andplaceInTree(FR4's move announcements,placeInTreeadding the parent),refused(a move past a rejected row),notMoved(FR4b's move the app did not apply),modeDone(leaving reorder mode), andunnamedItem(what announcements call an item with no text, such as "Item 2"); - shown labels:
handle(the handle's name, "Reorder" and the item's label),handleVerb("Reorder" alone, read before the row's own label when that label names the handle),unnamedHandle(the handle of an item with no text, such as "Reorder item 3"),handleHint(the handle's description of dragging and reorder mode),moveUp,moveDown,moveLeft, andmoveRight(the hint's move buttons), anddone(the hint's Done).
Every key is optional. An absent key falls back to the catalog message, translated when a collection renders under a provider and English without one; a given string replaces that message, including over a provider's translation. A templated message's key takes the catalog's ICU template with the same arguments, such as
place's label, position, count, and neighbors, ordropped's position and count. Implementation gap: not built;labelsdoes not exist yet, so every string is the catalog's.- announcements:
FR2 — Present means enabled. A collection that accepts reordering takes the object through one
reorderableprop; there is no separate boolean. With the prop absent the collection renders no handle, registers no reorder listener, and loads no reorder code: a collection imports none of it until the object is passed.FR3 — Every collection drags the same way. Each adopting collection wires the object to its own internal drag, keyboard, and assistive-technology paths, and the behavior is the same in every one:
- a drag starts from a row's handle (
design:ordered-collection-reorderingDR1); with a mouse, or a pen where the primary pointer is fine, a drag from the handle starts without a hold; a finger, or a pen where the primary pointer is coarse, keeps the hold, which picks the row up atspec:AST-094's values, and a flick still scrolls; - a held drag near the scroll container's edge scrolls it toward that edge, faster the nearer it is, and stops at the end;
- a drag commits once, at the drop (DR4), and
onReorderis called once for it; a cancelled drag calls nothing; - under Reduce Motion the moving preview still follows the finger or pointer,
and the other rows and the drop take their places without travel
(
design:reduced-motionDR1–DR3; a mouse drop follows DR2 on a coarse primary pointer and DR3 otherwise).
- a drag starts from a row's handle (
FR4 — Reorder mode is the one path without a drag. Each reorderable row's handle is a toggle button named "Reorder" and the row's label, with
aria-pressed. Activating it, by click, Enter, or Space, enters reorder mode for that item, and a mouse, a keyboard, and assistive technology all use it (spec:AST-094FR39). In reorder mode:- the arrow keys move the item along the layout axis: Up and Down in a
vertical collection, Left and Right in a horizontal one, and all four in
a two-dimensional layout such as a grid or a wrapping board, where Left
and Right move to the previous and next position in reading order,
mirrored in right-to-left, and Up and Down move to the same column in the
previous or next row, or to that row's last position when it is shorter;
rows and columns come from the measured layout, and
tostays the final index in the full order; in a tree, Up and Down move among visible positions, and Left and Right move the item out of or into a parent whereisReorderableallows; - each move commits at once through
onReorder({ key, to }), so the data, the screen, and the announcement always agree; - each move is announced once, after it renders, through the shared polite
announcement channel, inside a modal as
spec:AST-086FR14 requires, naming the item, its position and count, and its neighbors, such as "Milk, position 3 of 5, after Eggs, before Bread"; the first and last positions say "at the top" and "at the end", a two-dimensional layout adds the row and column, such as "Milk, row 2, column 3, position 8 of 12", and a tree adds the parent; - a move past a row
isReorderablerejects at either end of the collection is refused and announced, such as "Can't move past Pinned"; a rejected row in the middle is passed over, as a drag passes it (FR1); - focus stays on the handle, and the row scrolls into view;
- Escape, or activating the handle again, leaves reorder mode and keeps every move, announcing "Done" with the item's position, such as "Done, Milk at position 3 of 5";
- while the item is in reorder mode, the same accent insertion line a drag
shows marks the item's place, moving with each move
(
design:ordered-collection-reorderingDR7); - while the item is in reorder mode, a hint anchored to it shows the moves for its axis and a Done control, with the same layer, anchoring, and theme roles as Core's keyboard hint, and stays until the mode ends; each move in the hint is a button that does exactly what its key does, with the same announcement and focus on the handle, and Done leaves the mode as Escape does, so a pointer or a finger can reorder by tapping the handle, then the move buttons, then Done;
- the hint is a part named in each adopting collection's anatomy; it is a
layer that follows
family:overlay-dismissal; it uses the layer, anchoring, and theme roles of Core's keyboard hint, whose public API is unchanged, and unlike that hint its buttons take taps and are exposed to assistive technology.
- the arrow keys move the item along the layout axis: Up and Down in a
vertical collection, Left and Right in a horizontal one, and all four in
a two-dimensional layout such as a grid or a wrapping board, where Left
and Right move to the previous and next position in reading order,
mirrored in right-to-left, and Up and Down move to the same column in the
previous or next row, or to that row's last position when it is shorter;
rows and columns come from the measured layout, and
FR4a — An app can start reorder mode. The object exposes
start(key), which enters FR4's reorder mode for that item from the app's own UI, such as a toolbar button or a Move item in a menu. Focus moves to that item's handle, which scrolls into view, the hint appears, and the announcements and exits are FR4's. A key that is not reorderable, not mounted, or not found does nothing and warns in development. The mode ends through Escape, Done, the handle, or the item unmounting, so there is nostop. Beside FR4b'sattach, nothing else on the object is public;startand the handle enter the same mode.FR4b — Plain elements attach without React. The object exposes
attach(container, {items}), whereitems()returns one{key, element, handle}per item in order, and it returns{detach}. Implementation gap: not built; the object has noattachyet. An attached container gets FR3's drag, FR4's reorder mode on each handle, and their announcements, with no collection component;positionsandisReorderableapply as they do for a collection.attachgives eachhandleFR4's role and toggle state and names it with "Reorder" and the item's name: the item element's accessible name, else its text content, with a development warning when both are empty; it puts each handle in the Tab order; a rejected item's handle, or a keyless item's, gets none of this and starts no drag;start(key)reaches attached items as it reaches a collection's; and it renders FR4's hint as an element it owns. A move commits whenitems()reports the new order afteronReorder:attachannounces it and plays the drop then; while a modal dialog encloses the container,attachannounces through a persistent polite container inside that dialog, asspec:AST-086FR14 shapes it for Astryx modals; and a move whose order has not changed by the end of the task that ranonReorderis refused and announced, such as "Can't move King of hearts". Once a move commits,attachfocuses the moved item's handle asitems()returns it and scrolls it into view, so focus stays on the handle however the app moved or re-rendered the item.attachtakes each string from the object'slabels(FR1), an absent key falling back to the shipped English catalog, and formats numbers as a component outside a provider does (architecture:internationalizationINV3, INV3a). Implementation gap: not built;attachuses the shipped English catalog for every string.detachends any drag or reorder mode in progress, calling nothing, and removes every listener, observer, timer, element (that container included), and attributeattachadded, restoring each handle's own role, name, and tab order; and creating or importing the object does no DOM work, so it is safe on the server.FR5 — Reordering adds at most one element to a row. The one added element is the handle, the interactive drag target, with its role. Its grip is decoration, drawn by a pseudo-element or a theme-role glyph, not by elements. While a row is dragged, the source row stays in place, dimmed, and one moving preview follows the pointer (
design:ordered-collection-reordering): the preview is the one transient copyarchitecture:component-style-authoringINV7 allows, inert, hidden from assistive technology, and removed at the drop. Reorder listeners are per collection or on the document, never per row (spec:AST-094FR24).FR6 — Stable from the start.
createReorderable, its options, and a collection'sreorderableprop are stable public Core API: no_experimentalname and no experimental subpath (DEC-1).spec:AST-017FR21 and DEC-28 apply only to an API chosen as experimental.FR7 — Admitted and documented as public API.
reorderableis caller intent no collection can derive (spec:AST-002FR1, DEC-1), and its thresholds stay internal (spec:AST-002FR3).createReorderablehas its own canonical descriptor and each adopting collection's descriptor documentsreorderable(spec:AST-039FR1, FR3).FR8 — One public shape for the job. A collection that reorders uses this object and no other public reorder API.
Current-state impact
component:Listgainsreorderableas the first adopter.- No collection in Core reorders by drag today. Tokenizer reports a
reorderchange (spec:AST-056); bringing it onto this object is follow-up work. A Lab collection that reorders adopts this object.
Verification
| Contract | Verification | Representative states | Mutation or failure expectation |
|---|---|---|---|
| FR1, FR6–FR8 | Public-API review, type tests, and descriptor checks | the factory's options, ReorderableLabels' keys included; a collection's reorderable type; the factory's and List's descriptors |
an extra gesture, timing, or animation option, an experimental name or subpath, a missing descriptor, a second public reorder API, a string the object announces or shows that no labels key replaces, or a translator option, fails |
| FR1 copies | Unit tests that load a second copy of List's reorder context and of the internal reorder entry | a copied List reading an object the package made; the package List reading an object a copied entry adapted | a copy that reads undefined where the package put the machinery, in either direction, fails |
| FR2 | Bundle and runtime check of a collection with and without the prop | without the prop; with the prop | reorder code in the bundle, a handle, or a reorder listener without the prop fails; the measured cost is recorded in the pull request |
| FR3 | Browser tests with real touch input and a mouse (spec:AST-013 FR10) |
a hold and drag; a flick; a drop; a cancelled drag; Reduce Motion; a fanned hand with custom positions; a list without them; a positions array of the wrong length; a tree with positions; custom positions beside a rejected end row; a pen drag on a fine and on a coarse primary pointer |
a drag that starts off the handle, a commit before the drop, two callbacks for one drag, a callback on cancel, travel under Reduce Motion, a drop that ignores positions of the right length, a wrong-length array or a tree whose drops do not come from the measured layout, a drop outside the drop range, a mouse drag, or a pen drag on a fine primary pointer that waits for a hold, or a pen drag on a coarse primary pointer that starts without one, or a call without positions whose behavior changes fails |
| FR3 autoscroll | Browser tests with a mouse of a drag held near a scroll edge, and unit tests of the autoscroll step and its timer | a row held near the page's bottom edge, and held there until the list's end is in view; a row held near the bottom of a box the list scrolls in; the step at each depth past the edge; the timer at an edge | a held drag near an edge that scrolls nothing, scrolls the page while a box holds the list, scrolls away from the edge, keeps one speed nearer the edge, or scrolls past the end fails |
| FR4 | Keyboard, mouse, and announcement-routing tests of reorder mode (spec:AST-009 FR17) |
entering by click, Enter, and Space; arrows in vertical, horizontal, and grid collections; Up, Down, Left, and Right in a tree; each move's announcement at the top, middle, and end; a move past a rejected row; Escape and a second activation; focus and scroll after each move | a move that does not commit at once, an announcement missing, repeated, or before render, a move past a rejected row at either end, or a mid-list rejected row that blocks a move, focus leaving the handle, or moves undone on exit fails |
| FR4 hint | Browser tests with a mouse, a finger, and a keyboard | the hint's axis in vertical, horizontal, and grid collections; each move button and Done; a tap-only reorder; the hint's theme roles | a hint off the keyboard hint's layer, anchoring, or theme roles, buttons that ignore taps or are hidden from assistive technology, a button whose move or announcement differs from its key, focus leaving the handle, or a hint that outlives the mode fails |
| FR4 two-dimensional | Keyboard and announcement-routing tests on a wrapping card grid, left-to-right and right-to-left | Left and Right across a row end; Up and Down between full rows and into a short last row; announcements with row and column; the hint's four buttons; a resize that changes the column count | a move off reading order, a mirrored direction wrong in right-to-left, a short-row move that is not clamped to its last position, a missing row or column, or a column count read from anything but layout fails |
| FR4a | Keyboard, mouse, and announcement-routing tests of start(key) |
start from a context-menu item and a toolbar button; a key that is not reorderable, not mounted, or unknown; an object re-created each render; one object on two collections |
start that does not focus and scroll to the handle, a hint or announcement that differs from the handle's mode, a missing-key call that throws or acts, or a two-collection call without a development warning fails |
| FR4b | Browser tests of attach on plain elements with a mouse, a finger, a pen, and the keyboard, and listener counts after detach |
a drag, a cancelled drag, reorder mode, a fanned layout with positions, a move the app applies and one it does not, detach mid-drag, a server import, a page in another language with every labels key given and with none, a given key under a provider, an item element with no accessible name, an item isReorderable rejects, a keyless item, start(key) on an attached item, a handle with its own tabindex="-1", a container inside a modal dialog the page opens, one object attached to two containers, a pen drag on a fine and on a coarse primary pointer, a move the app applies by moving the item's element and one by re-rendering it |
a missing drag, mode, or announcement on plain elements; a handle without FR4's role, pressed state, or name, one named "Reorder" alone when the item has text, or one outside the Tab order; a rejected or keyless item whose handle is a Reorder toggle or can be dragged; a start(key) that does not reach an attached item; a move announced before items() reports it, or one the app did not apply left unrefused; a drag or mode still running, or a listener, observer, hint element, handle attribute, or changed tab order left, after detach, a string other than its given labels key or, without one, the shipped English catalog's, an announcement inside a page-opened modal that reaches only the page-body channel, a move between two containers or a start there without the development warning, a pen drag on a fine primary pointer that waits for a hold, or one on a coarse primary pointer that starts without one, focus not on the moved item's handle after a move, or DOM work at import fails. Evidence gap: labels is not built, so no test covers a given key yet. |
| FR5 | Element and listener counts of a list with and without the prop | a row at rest; a row picked up; a row dropped | more than one added element per row, a grip drawn with elements, a per-row listener, a second preview, a source that leaves its place, a preview left after the drop, or a preview that assistive technology reaches, fails |
Decision log
DEC-1 — Reorderable is stable public API
Reference: spec:AST-103/DEC-1
Decider: cixzhang, 2026-10-25
Reordering is a capability callers build on, so createReorderable and a
collection's reorderable prop are stable public API from the start, with no
experimental name or subpath.
Rejected: shipping it as experimental first.
DEC-2 — A predicate keeps a row in place
Reference: spec:AST-103/DEC-2
Decider: cixzhang, 2026-10-25
Some rows must not move, such as a pinned first row, and a person should see
that before trying. An optional isReorderable(key) predicate marks them: the row
shows no handle and cannot be picked up, as a UIKit table's canMoveRow does.
The name follows Astryx's is… predicate convention.
Rejected: no per-row control, with unwanted moves ignored after the drop.
DEC-3 — A move names the item by its key
Reference: spec:AST-103/DEC-3
Decider: cixzhang, 2026-10-25
onReorder receives the moved item's key and its new position, and
isReorderable receives a key, so the contract names items by key everywhere. A
key stays correct when a list is virtualized and when a tree moves an item
between parents, where a pair of indices would not. A caller that filters the
items it passes maps to back to its full list.
Rejected: onReorder(from, to) with a pair of positions.
DEC-4 — The reorder key comes from the data
Reference: spec:AST-103/DEC-4
Decider: cixzhang, 2026-10-25
React does not pass key to a component, so a collection cannot rely on it.
A ListItem names its item with one itemKey prop, and a data collection
without an identity of its own takes idKey in Table's shape, a field name
or a function of the item, so the same job keeps one name. itemKey is a new name because no row prop
carries item identity today: value on option-like rows is the selected value
a form reads, a different job. A collection whose items already carry an
identity, such as TreeList's id or Table's idKey, uses it rather than a
second one, since no new API shares a job with an existing one.
Rejected: reading each direct child's React key.
DEC-5 — Reorder mode, not a move menu, is the path without a drag
Reference: spec:AST-103/DEC-5
Decider: cixzhang, 2026-10-25
Move menus are tiring for keyboard users. The handle instead toggles a reorder mode in which the arrow keys move the item and each move is announced with its position and neighbors. Each move commits at once, so leaving the mode keeps the moves and the app never undoes several commits; focus stays on the handle until Escape or a second activation.
While the mode is on, a hint anchored to the item shows the moves and Done, and its glyphs are buttons, so a sighted person who does not want to drag can tap through the same moves; it reuses the keyboard hint's layer rather than a second hint pattern.
Rejected: a menu of Move before and Move after.
DEC-6 — One labels object holds every string
Reference: spec:AST-103/DEC-6
Decider: cixzhang, 2026-11-01
A page without a provider, such as one attaching plain elements, still needs
its own language, and the object announces and shows many strings. One
optional labels object holds them, each key falling back to the catalog
message, as architecture:internationalization INV3a gives a factory with
more than one string; translation itself stays with the provider.
Rejected: a translator-function option, and one flat option per string.
Open questions
None.