Skip to content

Commit 10c7be4

Browse files
committed
fix: other cases failing
1 parent 50ad67f commit 10c7be4

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

packages/vaul-vue/src/DrawerContent.vue

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { DialogContent } from 'radix-vue'
44
import { injectDrawerRootContext } from './context'
55
66
const {
7+
open,
78
isOpen,
89
isVisible,
910
snapPointsOffset,
@@ -34,7 +35,10 @@ function handlePointerDownOutside(event: Event) {
3435
keyboardIsOpen.value = false
3536
3637
event.preventDefault()
37-
if (!dismissible.value)
38+
39+
if (dismissible.value)
40+
emitOpenChange(false)
41+
if (!dismissible.value || open.value !== undefined)
3842
return
3943
4044
closeDrawer()
@@ -63,6 +67,10 @@ watch(
6367
@pointermove="onDrag"
6468
@pointerup="onRelease"
6569
@pointer-down-outside="handlePointerDownOutside"
70+
@escape-key-down="(event) => {
71+
if (!dismissible)
72+
event.preventDefault()
73+
}"
6674
>
6775
<slot />
6876
</DialogContent>

packages/vaul-vue/src/DrawerRoot.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
1414
const props = withDefaults(defineProps<DrawerRootProps>(), {
1515
open: undefined,
16+
defaultOpen: undefined,
1617
fixed: undefined,
1718
dismissible: true,
1819
activeSnapPoint: undefined,
@@ -43,7 +44,7 @@ const emitHandlers = {
4344
emitRelease: (open: boolean) => emit('release', open),
4445
emitClose: () => emit('close'),
4546
emitOpenChange: (o: boolean) => {
46-
open.value = o
47+
emit('update:open', o)
4748
},
4849
}
4950
@@ -58,17 +59,22 @@ const { closeDrawer, hasBeenOpened, modal, isOpen } = provideDrawerRootContext(
5859
)
5960
6061
function handleOpenChange(o: boolean) {
62+
if (open.value !== undefined) {
63+
emitHandlers.emitOpenChange(o)
64+
return
65+
}
6166
if (!o) {
6267
closeDrawer()
6368
}
6469
else {
6570
hasBeenOpened.value = true
66-
open.value = o
71+
isOpen.value = o
6772
}
6873
}
6974
</script>
7075

7176
<template>
77+
{{ isOpen }}
7278
<DialogRoot
7379
:open="isOpen"
7480
:modal="modal"

packages/vaul-vue/src/context.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ComponentPublicInstance, Ref } from 'vue'
22
import { createContext } from 'radix-vue'
33

44
export interface DrawerRootContext {
5+
open: Ref<boolean>
56
isOpen: Ref<boolean>
67
modal: Ref<boolean>
78
hasBeenOpened: Ref<boolean>

packages/vaul-vue/src/controls.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
113113
fadeFromIndex,
114114
} = props
115115

116-
const isOpen = ref(open.value)
116+
const isOpen = ref(open.value ?? false)
117117
const hasBeenOpened = ref(false)
118118
const isVisible = ref(false)
119119
const isDragging = ref(false)
@@ -373,7 +373,7 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
373373
})
374374

375375
// Don't reset background if swiped upwards
376-
if (shouldScaleBackground.value && currentSwipeAmount && currentSwipeAmount > 0 && isOpen) {
376+
if (shouldScaleBackground.value && currentSwipeAmount && currentSwipeAmount > 0 && isOpen.value) {
377377
set(
378378
wrapper,
379379
{
@@ -408,9 +408,8 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
408408
scaleBackground(false)
409409
restorePositionSetting()
410410

411-
isVisible.value = false
412411
window.setTimeout(() => {
413-
emitOpenChange(false)
412+
isVisible.value = false
414413
isOpen.value = false
415414
}, 300)
416415

@@ -492,16 +491,22 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
492491
resetDrawer()
493492
}
494493

495-
watch(open, (o) => {
494+
watch(isOpen, (o) => {
496495
if (o) {
497496
openTime.value = new Date()
498497
scaleBackground(true)
498+
}
499+
emitOpenChange(o)
500+
}, { immediate: true })
501+
502+
watch(open, (o) => {
503+
if (o) {
499504
isOpen.value = o
505+
hasBeenOpened.value = true
500506
}
501507
else {
502508
closeDrawer()
503509
}
504-
emitOpenChange(o)
505510
}, { immediate: true })
506511

507512
function scaleBackground(open: boolean) {
@@ -592,6 +597,7 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
592597
}
593598

594599
return {
600+
open,
595601
isOpen,
596602
modal,
597603
keyboardIsOpen,

0 commit comments

Comments
 (0)