UI LibraryUI Library
Guide
Components
Styling
Repo
Guide
Components
Styling
Repo
  • Guide

    • Introduction
    • Getting Started
  • Components

    • CataUiAccordion
    • CataUiAccordionItem
    • CataUiAlert
    • CataUiAnchorMenu
    • CataUiBadge
    • CataUiButton
    • CataUiCollapse
    • CataUiDraggable
    • CataUiDropdown
    • CataUiDropover
    • CataUiFileTree
    • CataUiIcon
    • CataUiIconSwitch
    • CataUiInput
    • CataUiInputCheckbox
    • CataUiInputColor
    • CataUiInputDate
    • CataUiInputGroup
    • CataUiInputRadio
    • CataUiInputSearch
    • CataUiInputSelect
    • CataUiMasonry
    • CataUiMasonryTile
    • CataUiLogo
    • CataUiModal
    • CataUiPaginate
    • CataUiProgress
    • CataUiSpinner
    • CataUiStatusLabel
    • CataUiSwitch
    • CataUiTable
    • CataUiTableAG
    • CataUiTableFooter
    • CataUiTabs
    • CataUiTabSwitch
    • CataUiTooltip
  • Styling

    • Colors
    • Icons
    • Typography
    • Utils

CataUiDraggable

The CataUiDraggable component provides a flexible and intuitive drag-and-drop interface for sorting and transferring items between lists. It's built as a wrapper around vue.draggable, offering a simplified API while maintaining all the powerful features of the underlying library.

  • Draggable Item 1-1
  • Draggable Item 1-2
  • Draggable Item 1-3
  • Draggable Item 2-1
  • Draggable Item 2-2
  • Draggable Item 2-3
<CataUiDraggable
    animation="150"
    group="dragitems"
    item-key="id"
    v-model="draggableItems1">
    <template #item="{ element }">
        {{ element.label }}
    </template>
</CataUiDraggable>
<CataUiDraggable
    animation="150"
    group="dragitems"
    item-key="id"
    v-model="draggableItems2">
    <template #item="{ element }">
        {{ element.label }}
    </template>
</CataUiDraggable>

Tips

The CataUiDraggable component is a wrapper for vue.draggable. All props and events from vue.draggable are also available in this component.

For more information and advanced usage, see Vue Draggable

Props

PropDescriptionTypeDefaultRequired
animationAnimation speed in millisecondsNumber150false
forceFallbackForce the fallback option even if native HTML5 drag & drop is availableBooleantruefalse
ghost-classClass name for the drop placeholderString'ghost'false
groupGroup name for the lists that should be able to share itemsStringfalse
item-keyUnique identifier field name in your itemsString'id'false
revertOnSpillRevert drag operation when the item is dropped outside of a valid listBooleantruefalse
tagHTML tag used for the list containerString'ul'false
v-modelAn array of draggable elementsArraytrue

Events

EventDescriptionParameters
endTriggered when a drag operation endsNone
startTriggered when a drag operation startsNone
unchooseTriggered when an item is no longer being draggedNone

Slots

SlotDescriptionProps
itemTemplate for each draggable item{ element }

Example Usage

Here's a complete example of how to use CataUiDraggable with two connected lists:

<script setup>
import { ref } from 'vue';

// Data structure for draggable items
const draggableItems1 = ref([
    {
        id: 11,        // Required unique identifier matching the item-key prop
        label: 'Draggable Item 1-1'
    },
    {
        id: 12,
        label: 'Draggable Item 1-2'
    },
    {
        id: 13,
        label: 'Draggable Item 1-3'
    },
]);

const draggableItems2 = ref([
    {
        id: 21,
        label: 'Draggable Item 2-1'
    },
    {
        id: 22,
        label: 'Draggable Item 2-2'
    },
    {
        id: 23,
        label: 'Draggable Item 2-3'
    },
]);

// Optional: Track when the drag operation starts and ends
function onDragStart() {
    console.log('Drag operation started');
}

function onDragEnd() {
    console.log('Drag operation ended');
}
</script>

<template>
    <div class="lists-container">
        <!-- First draggable list -->
        <CataUiDraggable
            animation="150"
            group="dragitems"
            item-key="id"
            v-model="draggableItems1"
            @start="onDragStart"
            @end="onDragEnd">
            <template #item="{ element }">
                {{ element.label }}
            </template>
        </CataUiDraggable>
        
        <!-- Second draggable list that shares the same group -->
        <CataUiDraggable
            animation="150"
            group="dragitems"
            item-key="id"
            v-model="draggableItems2">
            <template #item="{ element }">
                {{ element.label }}
            </template>
        </CataUiDraggable>    </div>
</template>

<style scoped>
.lists-container {
    display: flex;
    gap: 20px;
}
</style>

Advanced Usage Notes

  1. Multiple Connected Lists: Use the same group prop value to allow items to be dragged between lists.

  2. One-Way Transfer: To create a one-way transfer between lists, use an object for the group prop:

    <!-- Source list (can only move items from) -->
    <CataUiDraggable :group="{ name: 'items', pull: 'clone', put: false }" ... />
    
    <!-- Target list (can only receive items) -->
    <CataUiDraggable :group="{ name: 'items', pull: false, put: true }" ... />
    
  3. Item Validation: Use the @add event to validate items before they're added to a list.

  4. Custom Drag Handle: For more complex items, use the handle prop to specify a CSS selector for the drag handle.

Prev
CataUiCollapse
Next
CataUiDropdown