Skip to content

Commit 9030f77

Browse files
authored
Merge pull request #4 from billyct/add-tag-prop
Add tag prop
2 parents 45a3ccf + 54967fe commit 9030f77

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { Sortable } from 'sortablejs-vue3'
4242
<Sortable
4343
:list="elements"
4444
item-key="id"
45+
tag="div"
4546
:options="options"
4647
>
4748
<template #item="{element, index}">
@@ -55,6 +56,8 @@ import { Sortable } from 'sortablejs-vue3'
5556

5657
4. The `list` and `item-key` props are necessary. The `options` prop is an object that can contain any SortableJS option. You can find a full list of them here: https://github.com/SortableJS/Sortable#options
5758

59+
5. The `tag` prop is an optional prop, it's the HTML node type of the element that creates an outer element for the included slot. the default value is `div`
60+
5861
### Events
5962
You can listen to Sortable events by adding the listeners to the `Sortable` component. For example:
6063

src/components/Sortable.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const props = defineProps({
3434
default: "",
3535
required: true,
3636
},
37+
tag: {
38+
type: String as PropType<string>,
39+
default: "div",
40+
required: false,
41+
}
3742
});
3843
3944
const emit = defineEmits<{
@@ -84,13 +89,17 @@ onUnmounted(() => {
8489
</script>
8590

8691
<template>
87-
<div ref="containerRef" :class="$props.class">
92+
<component
93+
ref="containerRef"
94+
:is="$props.tag"
95+
:class="$props.class"
96+
>
8897
<slot
8998
v-for="(item, index) of list"
9099
:key="item[$props.itemKey!]"
91100
:element="item"
92101
:index="index"
93102
name="item"
94103
></slot>
95-
</div>
104+
</component>
96105
</template>

0 commit comments

Comments
 (0)