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

next: fix scroll restoration #98

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/sharp-actors-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vaul-svelte": patch
---

next: fix scroll restoration
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.2.7",
"prettier-plugin-tailwindcss": "0.6.8",
"svelte": "^5.0.0-next.260",
"svelte": "^5.0.0",
"svelte-eslint-parser": "^0.41.1",
"wrangler": "^3.44.0"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/vaul-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"!dist/**/*.spec.*"
],
"peerDependencies": {
"svelte": "5.0.0-next.1"
"svelte": "^5.0.0"
},
"devDependencies": {
"@sveltejs/kit": "^2.6.1",
"@sveltejs/package": "^2.3.5",
"@sveltejs/vite-plugin-svelte": "4.0.0-next.7",
"@sveltejs/vite-plugin-svelte": "4.0.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/svelte": "^5.2.1",
Expand All @@ -41,7 +41,7 @@
"autoprefixer": "^10.4.16",
"jsdom": "^24.1.0",
"publint": "^0.2.8",
"svelte": "^5.0.0-next.260",
"svelte": "^5.0.0",
"svelte-check": "^4.0.4",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
Expand All @@ -53,8 +53,8 @@
"types": "./dist/index.d.ts",
"type": "module",
"dependencies": {
"bits-ui": "1.0.0-next.15",
"svelte-toolbelt": "^0.4.2"
"bits-ui": "1.0.0-next.28",
"svelte-toolbelt": "^0.4.4"
},
"engines": {
"pnpm": ">=8.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
const mergedProps = $derived(mergeProps(restProps, contentState.props));
</script>

<DialogPrimitive.Content {...mergedProps}>
<DialogPrimitive.Content {...mergedProps} preventScroll={true}>
{@render children?.()}
<Mounted onMounted={(m) => (contentState.mounted = m)} />
</DialogPrimitive.Content>
21 changes: 20 additions & 1 deletion packages/vaul-svelte/src/lib/components/drawer/drawer.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { Dialog as DialogPrimitive } from "bits-ui";
import { box } from "svelte-toolbelt";
import { afterSleep, box } from "svelte-toolbelt";
import type { RootProps } from "./index.js";
import { noop } from "$lib/internal/helpers/noop.js";
import { useDrawerRoot } from "$lib/vaul.svelte.js";
Expand Down Expand Up @@ -88,8 +88,19 @@
container: box.with(() => container),
});

let bodyStyles: any;

function handleOpenChange(o: boolean) {
onOpenChange?.(o);

if (o && !nested) {
bodyStyles = document.body.style.cssText;
} else if (!o && !nested) {
afterSleep(TRANSITIONS.DURATION * 1000, () => {
document.body.style.cssText = bodyStyles;
});
}

if (!o && !nested) {
rootState.positionFixedState.restorePositionSetting();
}
Expand All @@ -111,13 +122,21 @@
document.body.style.pointerEvents = "auto";
}
}

$effect(() => {
return () => {
if (nested) return;
document.body.style.cssText = bodyStyles;
};
});
</script>

<DialogPrimitive.Root
controlledOpen
open={rootState.open.current}
onOpenChange={(o) => {
rootState.onDialogOpenChange(o);
handleOpenChange(o);
}}
{...restProps}
/>
Expand Down
34 changes: 16 additions & 18 deletions packages/vaul-svelte/src/lib/vaul.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { untrack } from "svelte";
import {
type Box,
type Getter,
type ReadableBoxedValues,
type WithRefProps,
type WritableBox,
type WritableBoxedValues,
afterTick,
import type {
Box,
Getter,
ReadableBoxedValues,
WithRefProps,
WritableBox,
WritableBoxedValues,
} from "svelte-toolbelt";
import type { MouseEventHandler, PointerEventHandler } from "svelte/elements";
import { isInput, isVertical } from "./internal/helpers/is.js";
Expand Down Expand Up @@ -132,7 +131,6 @@ export class DrawerRootState {
this.autoFocus = props.autoFocus;
//
this.snapPointsState = new SnapPointsState(this);

this.positionFixedState = new PositionFixed(this);

$effect(() => {
Expand Down Expand Up @@ -228,13 +226,13 @@ export class DrawerRootState {
});
});

$effect(() => {
if (!this.modal.current) {
window.requestAnimationFrame(() => {
document.body.style.pointerEvents = "auto";
});
}
});
// $effect(() => {
// if (!this.modal.current) {
// window.requestAnimationFrame(() => {
// document.body.style.pointerEvents = "auto";
// });
// }
// });
}

setActiveSnapPoint = (snapPoint: string | number | null) => {
Expand Down Expand Up @@ -746,7 +744,7 @@ class DrawerOverlayState {

type DrawerContentStateProps = WithRefProps &
ReadableBoxedValues<{
onInteractOutside: (e: MouseEvent | TouchEvent | PointerEvent) => void;
onInteractOutside: (e: PointerEvent) => void;
onPointerDown: PointerEventHandler<HTMLDivElement>;
onPointerMove: PointerEventHandler<HTMLDivElement>;
onPointerUp: PointerEventHandler<HTMLDivElement>;
Expand Down Expand Up @@ -855,7 +853,7 @@ class DrawerContentState {
// }
};

onInteractOutside = (e: MouseEvent | TouchEvent | PointerEvent) => {
onInteractOutside = (e: PointerEvent) => {
this.#onInteractOutsideProp.current(e);

if (!this.#root.modal.current || e.defaultPrevented) {
Expand Down
Loading