āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/sadmann7/diceui/components/sortable ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
npx shadcn@latest add "https://diceui.com/r/sortable"
```package-install
@dnd-kit/core @dnd-kit/modifiers @dnd-kit/sortable @dnd-kit/utilities @radix-ui/react-slot
```
</Step>
<Step>
Copy the refs composition utilities into your `lib/compose-refs.ts` file.
<ComponentSource name="compose-refs" />
</Step>
<Step>
Copy and paste the following code into your project.
<ComponentSource name="sortable" />
</Step>
</Steps>
Import the parts, and compose them together.
import * as Sortable from "@/components/ui/sortable";
<Sortable.Root>
<Sortable.Content>
<Sortable.Item >
<Sortable.ItemHandle />
</Sortable.Item>
<Sortable.Item />
</Sortable.Content>
<Sortable.Overlay />
</Sortable.Root>
Display a dynamic overlay when an item is being dragged.
<ComponentTabs name="sortable-dynamic-overlay-demo" scalePreview />Use ItemHandle as a drag handle for sortable items.
Use an array of primitives (string or number) instead of objects for sorting.
<ComponentTabs name="sortable-primitive-values-demo" />The main container component for sortable functionality.
<AutoTypeTable path="./types/docs/sortable.ts" name="RootProps" />
Container for sortable items. Multiple SortableContent components can be used within a Sortable component.
<AutoTypeTable path="./types/docs/sortable.ts" name="ContentProps" />
Individual sortable item component.
<AutoTypeTable path="./types/docs/sortable.ts" name="ItemProps" />
<DataAttributesTable attributes={[ { title: "[data-disabled]", value: "Present when the item is disabled.", }, { title: "[data-dragging]", value: "Present when the item is being dragged.", }, ]} />
A button component that acts as a drag handle for sortable items.
<AutoTypeTable path="./types/docs/sortable.ts" name="ItemHandleProps" />
<DataAttributesTable attributes={[ { title: "[data-disabled]", value: "Present when the item is disabled.", }, { title: "[data-dragging]", value: "Present when the parent sortable item is being dragged.", } ]} />
The component extends the base Button component and adds the following styles:
select-none for pointer eventscursor-grab when not dragging (unless flatCursor is true)cursor-grabbing when dragging (unless flatCursor is true)cursor-default when flatCursor is trueThe overlay component that appears when an item is being dragged.
<AutoTypeTable path="./types/docs/sortable.ts" name="OverlayProps" />
<KeyboardShortcutsTable shortcuts={[ { keys: ["Enter", "Space"], description: "Picks up the sortable item for reordering when released, and drops the item in its new position when pressed again.", }, { keys: ["ArrowUp"], description: "Moves the sortable item up in vertical orientation.", }, { keys: ["ArrowDown"], description: "Moves the sortable item down in vertical orientation.", }, { keys: ["ArrowLeft"], description: "Moves the sortable item left in horizontal orientation.", }, { keys: ["ArrowRight"], description: "Moves the sortable item right in horizontal orientation.", }, { keys: ["Esc"], description: "Cancels the sort operation and returns the item to its original position.", }, ]} />
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā