Repository navigation
[listbox] Add sorting providers using the drag engine - #3
Open
flaviendelangle wants to merge 57 commits into
Open
flaviendelangle wants to merge 57 commits into
flaviendelangle wants to merge 57 commits into
Conversation
flaviendelangle
force-pushed
the
listbox-base-ui-dnd
branch
from
August 14, 2026 10:47
b94fd12 to
09232bb
Compare
flaviendelangle
force-pushed
the
listbox-base-ui-dnd
branch
from
August 14, 2026 11:32
09232bb to
95146d8
Compare
# Conflicts: # docs/src/error-codes.json
`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
force-pushed
the
listbox-drag-engine-base
branch
from
October 9, 2026 08:18
5e6f6d5 to
0f4d946
Compare
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>
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
DragAndDropProviderwithKeyboardSortableProviderfor keyboard-only sorting andSortableProviderfor 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.onItemsReorder(values, eventDetails). It proposes the complete order, supports cancellation, reports keyboard or drag reasons, and includes group membership ineventDetails.order. Applications accept a move by rendering the proposed order; focus and announcements follow the accepted update.canMoveItemsandisItemSortingDisabledfor 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.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.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, andonDraggableDropcontrol acceptance and insertion. NativeonDropremains available for HTML drag-and-drop events. Disabled sorting targets reject ancestor fallback through the common sorting adapter.kind. Payloads contain picked-up item values, item IDs, collection identity, and application data fromgetDragPayload. Sorting and external-drop callbacks both expose aDragSourcethroughsource, with application payloads undersource.payload. Transfers remain application-owned.ItemDragHandlewithSortHandle, addSortPreview, and exposeItem.draggablePropsfor activation, modifiers, and drag callbacks. Custom placement uses normalized row coordinates and supports horizontal layouts and RTL.onDropPositionChangeexposes placement updates;onSortEndreports the final pointer outcome.data-moving) from the physically picked-up item (data-dragging). Replacedata-drop-targetanddata-drop-target-edgewithdata-drag-overand logicaldata-drop-position="before" | "after"states, shared by sorting and external drops.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.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.mdissue excluded.