生态产品多个设计器现已发布候选版本

查看生态总览
Skip to content

Sortable ​

Layout component. This page is the API reference, generated from the source code. Usage guidance and live examples are on the Chinese page.

Anatomy ​

Parts in bold are required.

data-scope="sortable": root · item · item-drag-trigger · drop-indicator · live-region

API reference ​

Descriptions of individual props, events and slots are written in Chinese and appear on the Chinese page.

Artifacts ​

LayerValue
Custom element<xh-sortable>
Vue componentsXhSortableDropIndicator XhSortableItem XhSortableItemDragTrigger XhSortableLiveRegion XhSortableRoot
ComposableuseSortable
State machinesortableMachine
Skin@xihan-ui/styles/sortable.css

Props ​

PropTypeRequired
idsstring[]Yes
orientationSortableAxis
disabledboolean
activationDistancenumber
autoScrollboolean
dirDirection
translationsPartial<SortableTranslations>
groupstring
listIdstring
onSort(details: SortableSortDetails) => void
onTransfer(details: SortableTransferDetails) => void
onDragStart(details: SortableDragStartDetails) => void
onDragEnd(details: SortableDragEndDetails) => void

Events ​

Custom elements put the payload in detail; Vue emits an event of the same name.

EventPayload
sortSortableSortDetails
transferSortableTransferDetails
drag-startSortableDragStartDetails
drag-endSortableDragEndDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhSortableItemdefaultSortableItemSlotProps
XhSortableItemDragTriggerdefault—
XhSortableRootdefaultSortableRootSlotProps

React adapter props ​

Only the props each component declares itself: DOM attributes inherited from ComponentPropsWithRef are left out, and root props already listed in the Props table are not repeated. The Vue counterpart is the slot table above.

React componentPropTypeRequired
XhSortableItemitemIdstringYes
XhSortableItemdisabledboolean
XhSortableItemchildrenSlotChildren<SortableItemSlotProps>
XhSortableItemDragTriggeritemIdstringYes
XhSortableItemDragTriggerdisabledboolean
XhSortableRootchildrenSlotChildren<SortableRootSlotProps>

State ​

The following names are internal to the state machine.

States: idle · pending · dragging

Events: ITEM.POINTER_DOWN · POINTER.MOVE · POINTER.END · POINTER.CANCEL · ITEM.PICKUP · KEY.MOVE · KEY.MOVE_LIST · KEY.DROP · KEY.CANCEL · GROUP.OVER · GROUP.LEAVE · GROUP.DROP · PRESS.START · PRESS.END

Guards: canSort · passedActivation · canPress

connect API ​

getXxxProps() returns the host attributes of the matching part.

MemberType
draggingboolean
activeIdstring | null
fromnumber
tonumber
modeSortableMode | null
itemsSortableItemState[]
getRootProps() => T['element']
getItemProps(props: SortableItemProps) => T['element']
getItemDragTriggerProps(props: SortableItemProps) => T['element']
getDropIndicatorProps() => T['element']
getLiveRegionProps() => T['element']

Accessibility ​

Keyboard ​

Specification: W3C APG. Each row is a stable behavior id that the conformance tests cover; the conditions and effects are described on the Chinese page.

KeysBehavior
Space / Entersortable.kbd.pickup
ArrowDown / ArrowRightsortable.kbd.next
ArrowUp / ArrowLeftsortable.kbd.prev
ArrowRight / ArrowDownsortable.kbd.next-list
ArrowLeft / ArrowUpsortable.kbd.prev-list
Space / Entersortable.kbd.drop
Escapesortable.kbd.cancel
Enter / Spacesortable.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-labeltranslations.root
rootrole'group'
item-drag-triggeraria-disabled'true' | 'false'
item-drag-triggeraria-labeltranslations.itemDragTrigger(name)
item-drag-triggeraria-pressed'true' | 'false'
item-drag-triggeraria-roledescriptiontranslations.itemDragTriggerRoleDescription
item-drag-triggerrole'button'
drop-indicatoraria-hidden'true'
live-regionaria-atomic'true'
live-regionaria-live'polite'
live-regionrole'status'

Style reference ​

Skin ​

@xihan-ui/styles/sortable.css is written against [data-scope="sortable"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-sortable in place of data-scope (same specificity) and sits in the xihan.components layer. Put overrides in xihan.overrides; the part selectors work as usual.

Data attributes ​

Produced by connect; valueless attributes are omitted while their condition does not hold.

PartAttributeValue
rootdata-disabled'' (present only while the condition holds)
rootdata-drag-modecontext.get('mode') | undefined
rootdata-dragging'' (present only while the condition holds)
rootdata-drop'inside' | undefined
rootdata-orientationprops.orientation
itemdata-animating'' (present only while the condition holds)
itemdata-disabled'' (present only while the condition holds)
itemdata-dragging'' (present only while the condition holds)
itemdata-indexString(item?.index ?? -1)
item-drag-triggerdata-disabled'' (present only while the condition holds)
item-drag-triggerdata-dragging'' (present only while the condition holds)
item-drag-triggerdata-pressed'' (present only while the condition holds)
item-drag-triggerdata-xh-action-control''
item-drag-triggerdata-xh-action-display'always'
item-drag-triggerdata-xh-action-profile'icon'
item-drag-triggerdata-xh-action-size'xs'
item-drag-triggerdata-xh-action-variant'ghost'
drop-indicatordata-orientationprops.orientation

CSS variables ​

The public override slots, generated from what the standalone skin actually consumes.

VariablePartCSS propertyStateDefault from
--xh-sortable-drag-bg-activeitem-drag-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-sortable-drag-bg-hoveritem-drag-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-sortable-drag-fgitem-drag-triggercolordefault--xh-fg-muted
--xh-sortable-drag-fg-disableditem-drag-triggercolordisabled--xh-fg-disabled
--xh-sortable-drag-fg-hoveritem-drag-triggercolordisabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-fg-default
--xh-sortable-drag-grip-hitem-drag-triggerblock-sizeempty--xh-space-3
--xh-sortable-drag-grip-witem-drag-triggerinline-sizeempty--xh-space-1
--xh-sortable-drag-icon-sizeitem-drag-trigger--xh-icon-sizedefault--xh-_action-profile-glyph-size
--xh-sortable-drag-radiusitem-drag-triggerborder-radiusdefault--xh-shape-control
--xh-sortable-drag-sizeitem-drag-triggerblock-size
inline-size
min-inline-size
default
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-sortable-drop-indicator-bgdrop-indicatorbackgrounddefault--xh-bg-brand
--xh-sortable-drop-indicator-radiusdrop-indicatorborder-radiusdefault--xh-shape-pill
--xh-sortable-drop-indicator-sizedrop-indicatorblock-size
inline-size
orientation=both
orientation=horizontal
orientation=vertical
--xh-stroke-thick
--xh-sortable-gaprootgapdefault--xh-space-2
--xh-sortable-item-opacity-draggingitemopacitydragging0.9
--xh-sortable-item-shadow-draggingitembox-shadowdragging--xh-elevation-lifted

Released under The MIT License