Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

determine which property is being used as a background before caching… #76

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions packages/vaul-vue/src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,12 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
}

watchEffect(() => {
const wrapper = document.querySelector('[vaul-drawer-wrapper]') ?? document.body

if (!isOpen.value && shouldScaleBackground.value && isClient) {
// Can't use `onAnimationEnd` as the component will be invisible by then
const id = setTimeout(() => {
reset(document.body)
reset(wrapper)
}, 200)

return () => clearTimeout(id)
Expand Down Expand Up @@ -560,25 +562,16 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
}, { immediate: true })

function scaleBackground(open: boolean) {
const wrapper = document.querySelector('[vaul-drawer-wrapper]')
const wrapper = document.querySelector<HTMLElement>('[vaul-drawer-wrapper]') ?? document.body
const backgroundPropertyName = wrapper.style.backgroundColor ? 'backgroundColor' : 'background'

if (!wrapper || !shouldScaleBackground.value)
return

if (open) {
// setting original styles initially
set(document.body, {
background: document.body.style.backgroundColor || document.body.style.background,
})
// setting body styles, with cache ignored, so that we can get correct original styles in reset
set(
document.body,
{
background: 'black',
},
true,
)

set(wrapper, {
[backgroundPropertyName]: wrapper.style[backgroundPropertyName],
borderRadius: `${BORDER_RADIUS}px`,
overflow: 'hidden',
...(isVertical(direction.value)
Expand All @@ -594,12 +587,21 @@ export function useDrawer(props: UseDrawerProps & DialogEmitHandlers): DrawerRoo
transitionDuration: `${TRANSITIONS.DURATION}s`,
transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
})
// setting body styles, with cache ignored, so that we can get correct original styles in reset
set(
wrapper,
{
[backgroundPropertyName]: 'black',
},
true,
)
}
else {
// Exit
reset(wrapper, 'overflow')
reset(wrapper, 'transform')
reset(wrapper, 'borderRadius')
reset(wrapper, backgroundPropertyName)
set(wrapper, {
transitionProperty: 'transform, border-radius',
transitionDuration: `${TRANSITIONS.DURATION}s`,
Expand Down