Skip to content

Commit 7cd4bf2

Browse files
authored
fix: body style persist after unmount (#96)
* fix: background style was persisiting * fix: not able to dismiss drawer when clicking on overlay * fix: dont prevent pointer down outside event * fix: dismissable case * Create strange-cheetahs-call.md
1 parent 96b4b60 commit 7cd4bf2

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

.changeset/strange-cheetahs-call.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"vaul-vue": patch
3+
---
4+
5+
fix body style persist after unmount, clicking overlay not dismissing drawer

packages/vaul-vue/src/DrawerContent.vue

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ function handlePointerDownOutside(event: Event) {
4141
if (keyboardIsOpen.value)
4242
keyboardIsOpen.value = false
4343
44-
event.preventDefault()
45-
46-
if (dismissible.value)
44+
if (dismissible.value) {
4745
emitOpenChange(false)
46+
}
47+
else {
48+
event.preventDefault()
49+
}
4850
}
4951
5052
function handlePointerDown(event: PointerEvent) {

packages/vaul-vue/src/controls.ts

-4
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,6 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
519519
}
520520
})
521521

522-
onUnmounted(() => {
523-
restorePositionSetting()
524-
})
525-
526522
function onRelease(event: PointerEvent) {
527523
if (!isDragging.value || !drawerRef.value)
528524
return

packages/vaul-vue/src/usePositionFixed.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export function usePositionFixed(options: PositionFixedOptions) {
2525
const scrollPos = ref(0)
2626

2727
function setPositionFixed(): void {
28+
// All browsers on iOS will return true here.
29+
if (!isSafari())
30+
return
31+
32+
// If previousBodyPosition is already set, don't set it again.
2833
if (previousBodyPosition === null && isOpen.value && !noBodyStyles.value) {
2934
previousBodyPosition = {
3035
position: document.body.style.position,
@@ -33,13 +38,16 @@ export function usePositionFixed(options: PositionFixedOptions) {
3338
height: document.body.style.height,
3439
}
3540

41+
// Update the dom inside an animation frame
3642
const { scrollX, innerHeight } = window
3743

38-
document.body.style.position = 'fixed'
39-
document.body.style.top = `-${scrollPos.value}px`
40-
document.body.style.left = `-${scrollX}px`
41-
document.body.style.right = '0px'
42-
document.body.style.height = 'auto'
44+
document.body.style.setProperty('position', 'fixed', 'important')
45+
Object.assign(document.body.style, {
46+
top: `${-scrollPos.value}px`,
47+
left: `${-scrollX}px`,
48+
right: '0px',
49+
height: 'auto',
50+
})
4351

4452
setTimeout(() => {
4553
requestAnimationFrame(() => {

0 commit comments

Comments
 (0)