Skip to content

[listbox] Add sorting providers using the drag engine - #3

Open
flaviendelangle wants to merge 57 commits into
listbox-drag-engine-basefrom
listbox-base-ui-dnd
Open

flaviendelangle wants to merge 57 commits into
listbox-drag-engine-basefrom
listbox-base-ui-dnd

Conversation

@flaviendelangle

@flaviendelangle flaviendelangle commented Aug 14, 2026 •

Copy link
Copy Markdown
Owner

This builds on Michal's original Listbox PR, replacing its Pragmatic DnD integration with the Base UI drag engine and aligning sorting and external-drop APIs with Tree.

The PR targets listbox-drag-engine-base, which combines the Listbox and drag-engine parent branches. Their unrelated changes are excluded from this diff.

Changes compared with the original Listbox implementation:

  • Replace DragAndDropProvider with KeyboardSortableProvider for keyboard-only sorting and SortableProvider for keyboard and pointer sorting. Ordinary items and keyboard-only sorting do not import the pointer drag implementation. Remove the Pragmatic DnD dependencies and Listbox-specific registration hook.
  • Replace the moved-items/reference-item/edge reorder event with onItemsReorder(values, eventDetails). It proposes the complete order, supports cancellation, reports keyboard or drag reasons, and includes group membership in eventDetails.order. Applications accept a move by rendering the proposed order; focus and announcements follow the accepted update.
  • Use canMoveItems and isItemSortingDisabled for shared keyboard and pointer restrictions. Sorting can be disabled without disabling selection. Movement metadata exposes item IDs, values, indices, and group IDs; disabled state stays internal.
  • Add reorderOn="move" alongside the default drop-time reordering. Cancellation restores the previous order when it does not conflict with external reorders, while preserving item edits, deletions, and newly inserted items. Transaction helpers handle deferred updates, unmounting, and conflicting external reorders. Accepted external drops restore any live sorting preview before the application performs the transfer.
  • Add ItemExternalDropTarget, a complete option that accepts incoming drags and retains selection and keyboard behavior. Each row has one drop-target registration: same-list drags belong to sorting, and incoming drags use the explicit target. accept, canDrop, dropDisabled, getDropPosition, and onDraggableDrop control acceptance and insertion. Native onDrop remains available for HTML drag-and-drop events. Disabled sorting targets reject ancestor fallback through the common sorting adapter.
  • Support outgoing and cross-list drags through an explicit provider kind. Payloads contain picked-up item values, item IDs, collection identity, and application data from getDragPayload. Sorting and external-drop callbacks both expose a DragSource through source, with application payloads under source.payload. Transfers remain application-owned.
  • Replace ItemDragHandle with SortHandle, add SortPreview, and expose Item.draggableProps for activation, modifiers, and drag callbacks. Custom placement uses normalized row coordinates and supports horizontal layouts and RTL. onDropPositionChange exposes placement updates; onSortEnd reports the final pointer outcome.
  • Distinguish all items participating in a drag (data-moving) from the physically picked-up item (data-dragging). Replace data-drop-target and data-drop-target-edge with data-drag-over and logical data-drop-position="before" | "after" states, shared by sorting and external drops.
  • Support explicit group IDs and group-aware reorder proposals. Destination indices remain relative to the entire Listbox, including groups; Tree indices are parent-relative. Use stable per-item sorting IDs independently of application values and mutable positions.
  • Add configurable completion announcements through getAnnouncement. Preserve nested controls' keyboard behavior and let handled sorting shortcuts bubble with their default prevented. Keep nested Listbox sorting contexts isolated and preserve selection and focus through reorders.
  • Add keyboard-sorting, live-reordering, cross-list transfer, and library/archive demos in CSS Modules and Tailwind. Update existing sorting demos, fix dark mode across all ten demos, and document the APIs and transfer responsibilities.
  • Add regression coverage for controlled and deferred updates, selected-item moves, groups, cancellation, external targets, callback types, and keyboard event ownership, plus Chromium interaction tests for both styling variants of the transfer demos.

Validation: focused Listbox/shared-target/demo Chromium tests pass, along with the corresponding jsdom checks, TypeScript, formatting, stylelint, and generated API documentation. ESLint passes with the pre-existing local docs/CLAUDE.md issue excluded.

@flaviendelangle
flaviendelangle deleted the branch listbox-drag-engine-base August 19, 2026 09:59
@flaviendelangle
flaviendelangle deleted the listbox-base-ui-dnd branch August 19, 2026 10:04
@flaviendelangle
flaviendelangle restored the listbox-base-ui-dnd branch August 20, 2026 07:01
@flaviendelangle flaviendelangle changed the title [listbox] Use Base UI drag engine [listbox] Add sorting providers using the drag engine Sep 18, 2026
flaviendelangle and others added 11 commits October 2, 2026 08:42
`source.renderPreview()` is gone from the drag engine. A sort preview now
refreshes through `Draggable.updatePreview()`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copy Tree's versions of the shared sorting utilities. The active external
drop position now lives in the listbox store instead of a module-level
WeakMap, and the rows read their placement from the store, with external
drops taking precedence over sorting.

An external drop now reuses the context validated in canDrop instead of
resolving again after the source's terminal callbacks, which can change the
app state the resolver reads.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Nothing imports the barrel. Tree keeps its own copy of the sorting utilities.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Rename the demo folders drag-and-drop, live-reorder-dnd, and
sorting-keyboard to sorting, live-sorting, and keyboard-sorting, along
with their export names.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Rename the external drop's `listboxDestination` to `destination`.
- Rename the flat sorting event types to `ListboxSortableProvider*`, based
  on the engine's public `Draggable.Root` reason types.
- Make `onItemsReorder` required, since the listbox can't reorder its
  children itself.
- Remove `disabled` from `itemMetadata`. Disabled rows never reach
  `getDropPosition` or `canDrop`, so it was always `false`.
- Default the row's `previewKey` to its string or number value, so the
  settling preview finds a row that a drop remounts.
- Add `Listbox.Item.DraggableProps`, document `data-settling`, and align
  the sorting JSDoc and summaries with Tree.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…Change

- Sync the shared sorting utilities with Tree: `omitDragRecords()` now lives
  in SortableDropProvider, and useExternalDrop reports positions with the
  drag event details stripped of the engine's records.
- `ItemExternalDropTarget.onDropPositionChange` receives the same event
  details as `SortableProvider.onDropPositionChange`. Unmounting or disabling
  a hovered option clears its placement without an event; the leave the
  engine sends afterwards reports the `null` position.
- Leave the drag's own `canceled` flag out of the `onDropPositionChange`
  details at the end of a sort, which its type doesn't declare.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Announce a keyboard move blocked at the edge of the list, by a disabled
  neighbor, by `canMoveItems`, by canceling `onItemsReorder`, or by an item
  whose sorting is disabled: "Can't move a further down."
- Announce a message identical to the previous one again, by toggling a
  zero-width Word Joiner in the live region.
- `getAnnouncement` gets the `'blocked'` outcome and the arrow `direction`,
  and can return `undefined` to keep the default text.
- Document that external drops are pointer-only for now.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…rting

- Sortable options no longer set `aria-keyshortcuts`. Base UI never sets it,
  and the Alt+Arrow keys move the option rather than focus or activate it.
- Keyboard moves jump over disabled items in one step, so they reach the same
  slots as a pointer drop next to an enabled item. A move with only disabled
  items left in its direction stays blocked.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@flaviendelangle
flaviendelangle force-pushed the listbox-drag-engine-base branch from 5e6f6d5 to 0f4d946 Compare October 9, 2026 08:18
flaviendelangle and others added 13 commits October 9, 2026 10:41
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The drag engine now moves a drag onto its row when the row remounts, for example
after a live move into another group. The remounted row's declared payload only
identifies the row, so canceling lost the dragged items and focus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The payload already carries the dragged `itemIds` and their pickup `items`, so
`getDragPayload` and the payload's `data` field only relayed a function of them.
Tree.SortableProvider drops it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"Sort" orders items by value in the Mosaic Data Grid, which manual reordering
calls "reorder". Rename the public API to match, like the Tree:

- Listbox.SortableProvider → Listbox.ReorderProvider
- Listbox.KeyboardSortableProvider → Listbox.KeyboardReorderProvider
- Listbox.SortHandle / Listbox.SortPreview → Listbox.ReorderHandle / Listbox.ReorderPreview
- onSortEnd → onReorderEnd, SortEndEvent* → ReorderEndEvent*
- Listbox.Sorting{Item,Move,AnnouncementParameters,DropPosition} → Listbox.Reorder*

The docs sections and demos follow. The shared internals/sorting utilities and
the internal sorting hooks are unchanged. `isItemSortingDisabled` is renamed
separately, together with its polarity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reorder predicate read the opposite way from the rest of the family. Like
the Tree and Mosaic's `isRowReorderable`, it now returns whether an item can be
moved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… engine

Returning false from Listbox.ItemExternalDropTarget's canDrop rejected the drop
on the enclosing targets too, while the engine's canDrop skips the target and
lets an ancestor receive the drop. canDrop now accepts the engine's 'reject' for
a drop the enclosing targets must not receive either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Listbox.ItemExternalDropTarget's onDropPositionChange used the reorder
provider's event details type, and DropContext fed getDropPosition on the
provider but canDrop on the external target. The provider's context is now
PositionContext, like the external target's, and the external target's
one-sided DropPosition alias is removed in favor of Listbox.ReorderDropPosition.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reorder types named the referenced item `id`, while the drop contexts nested
the position in `itemMetadata`. They now use `itemId` for a reference and a flat
`index`/`groupId`, like the Tree. Affects Listbox.ReorderDropPosition, the drag
payload, Listbox.ReorderItem and the drop contexts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
onReorderEnd's `canceled` disagreed with the Draggable engine's `canceled` for the
same gesture: the engine reports a release outside any target as not canceled.
onReorderEnd now reports `outcome: 'moved' | 'unchanged' | 'canceled'`, the
union the reorder announcements already use. Also documents that
data-drag-over follows the resolved destination, and types the preview's
`source` with the Listbox's drag payload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Listbox.ReorderPreview and Listbox.ReorderHandle had no data attribute or CSS
variable tables because the Listbox didn't export modules for them. Adds
ListboxReorderPreviewDataAttributes, ListboxReorderPreviewCssVariables and
ListboxReorderHandleDataAttributes, mirroring the Draggable engine's preview and
handle attributes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
isItemReorderable received a wrapper object while the Listbox's other item
callbacks receive the value first. It is now called as
`isItemReorderable(value, { itemId, index, groupId })`. The second argument is
exported as Listbox.ReorderItemDetails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With reorderOn="move", moving the items away and back reported 'moved' to
onReorderEnd and announced a move, because the outcome only recorded that a
live move happened. The outcome now compares the final order with the one the
gesture started from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous fix compared the order before the drop. A release in another zone
of the last hovered row, before a hover frame ran, could make the drop's own
move restore the original order while onReorderEnd and the announcement
reported 'moved'. The outcome now compares the order after the drop with the
one the gesture started from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

This pull request has been inactive for 30 days. Please remove the stale label or leave a comment to keep it open. Otherwise, it will be closed in 15 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant