+
+
+
void) => any> },
beforeCancel: { type: Function as PropType<(hide: () => void) => any> },
ariaCloseLabel: useTranslationProp('$t:close'),
+ draggable: { type: Boolean, default: false },
+ draggablePosition: { type: Object, default: () => ({ x: '50%', y: '50%' }) },
})
useChildComponents(props)
@@ -260,6 +269,7 @@ const computedClass = computed(() => ({
'va-modal--mobile-fullscreen': props.mobileFullscreen,
'va-modal--fixed-layout': props.fixedLayout,
'va-modal--no-padding': props.noPadding,
+ 'va-modal--draggable': props.draggable,
}))
const {
@@ -402,16 +412,6 @@ watch(valueComputed, (newValue) => {
}
})
-onMounted(() => {
- if (valueComputed.value) { // case when open modal with this.$vaModal.init
- onShow()
- }
-
- if (isTopLevelModal.value) {
- trapFocusInModal()
- }
-})
-
onBeforeUnmount(() => {
onHide()
})
@@ -422,12 +422,44 @@ watch(isTopLevelModal, newIsTopLevelModal => {
}
}, { immediate: true })
+const initialPosition = toRef(props, 'draggablePosition')
+
+const containerRef = ref(null)
+
+const { positionStyle, startDrag } = useDraggable({
+ draggableRef: modalDialog,
+ containerRef,
+ isDraggable: props.draggable,
+ initialPosition,
+})
+
+const slots = useSlots()
+
+const slotsWithStartDrag = computed(() => {
+ return Object.keys(slots).filter(slot => {
+ if (!slots[slot]) { return false }
+
+ const tempSlotBind = { startDrag: () => {} }
+
+ const slotContent = slots[slot]?.(tempSlotBind) || []
+
+ return slotContent.some(vnode =>
+ vnode.props && Object.keys(vnode.props).includes('onMousedown'),
+ )
+ })
+})
+
+const handleStartDrag = computed(() => {
+ return slotsWithStartDrag.value.length ? () => {} : startDrag
+})
+
defineExpose({
show,
hide,
toggle,
cancel,
ok,
+ startDrag,
onBeforeEnterTransition,
onAfterEnterTransition,
onBeforeLeaveTransition,
@@ -442,7 +474,22 @@ const {
teleportedAttrs,
} = useTeleported()
-const slotBind = { show, hide, toggle, cancel, ok }
+const slotBind = { show, hide, toggle, cancel, ok, startDrag }
+
+onMounted(() => {
+ if (valueComputed.value) { // case when open modal with this.$vaModal.init
+ onShow()
+ }
+
+ if (isTopLevelModal.value) {
+ trapFocusInModal()
+ }
+
+ const { draggable, attachElement } = props
+ if (draggable && attachElement !== 'body') {
+ containerRef.value = document.querySelector(attachElement)
+ }
+})