Skip to content

Commit e22af4d

Browse files
fix: remove background after scale (#39)
* fix: remove background after scale * chore: include changeset * chore: update func * chore: update controls * chore: update logic to match upstream * chore: add `window` to setTimeout * chore: revert commit * fix: background color not removed --------- Co-authored-by: zernonia <[email protected]>
1 parent 86568ae commit e22af4d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.changeset/tame-teachers-confess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"vaul-vue": patch
3+
---
4+
5+
remove background on scale exit

packages/vaul-vue/src/controls.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { computed, ref, watch } from 'vue'
1+
import { computed, ref, watch, watchEffect } from 'vue'
22
import type { ComponentPublicInstance, Ref } from 'vue'
33
import { dampenValue, getTranslateY, reset, set } from './helpers'
44
import { TRANSITIONS, VELOCITY_THRESHOLD } from './constants'
@@ -423,6 +423,17 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
423423
}, TRANSITIONS.DURATION * 1000) // seconds to ms
424424
}
425425

426+
watchEffect(() => {
427+
if (!isOpen.value && shouldScaleBackground.value) {
428+
// Can't use `onAnimationEnd` as the component will be invisible by then
429+
const id = setTimeout(() => {
430+
reset(document.body);
431+
}, 200);
432+
433+
return () => clearTimeout(id);
434+
}
435+
})
436+
426437
function onRelease(event: PointerEvent) {
427438
if (!isDragging.value || !drawerRef.value)
428439
return
@@ -519,6 +530,11 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
519530
return
520531

521532
if (open) {
533+
// setting original styles initially
534+
set(document.body, {
535+
background: document.body.style.backgroundColor || document.body.style.background,
536+
});
537+
// setting body styles, with cache ignored, so that we can get correct original styles in reset
522538
set(
523539
document.body,
524540
{

0 commit comments

Comments
 (0)