Back to Woocommerce

README

packages/js/components/src/sortable/README.md

10.8.0-dev1.1 KB
Original Source

Sortable

This component provides a wrapper to allow dragging and sorting of items.

Usage

This component accepts any valid JSX elements as children. Adding a key to elements will provide a way to later identify the order of these elements in callbacks.

jsx
<Sortable onOrderChange={ ( items ) => console.log( 'Items have been reordered:', items ) }>
    <div key="item-1">List item 1</div>
    <div key="item-2">List item 2</div>
    <div key="item-3">List item 3</div>
</Sortable>

Props

NameTypeDefaultDescription
childrenJSX.Element | JSX.Element[]undefinedThe draggable items in the list
isHorizontalbooleanfalseDetermines if the sortable container should be droppable horizontally
onDragEndFunction() => nullA callback when an item is no longer being dragged
onDragOverFunction() => nullA callback when an item is being dragged over by another item
onDragStartFunction() => nullA callback when an item starts being dragged
onOrderChangeFunction() => nullA callback when the order of the items has been updated