-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
Drawer still dimissible with snappoints #161
Comments
This has been fixed in #166 |
Just updated to the last version, and it does not seems fixed anyway =( |
Please provide a codesandbox demo in that case, I'm unable to reproduce. |
Okey I did it @emilkowalski, first, here is the repo: vaul-dismissible-snappoints-issue 🔗 https://codesandbox.io/p/github/hypeproxy/vaul-dismissible-snappoints-issue/master |
It might be a misunderstood of the vision that you have of the a non-dismissible drawer actually. For me Drawer can be a required part of the UI, in my case, if the drawer is closed, the user cannot order nothing (the order summary is inside). |
I just tried this, it works as a fallback, but I'd prefer a real non-dismissible drawer. Don't work however with too small timeout, like 100ms. useEffect(() => {
if (!open) setTimeout(() => {
setOpen(true);
setSnap(snapPoint1 || "290px");
}, 500);
}, [open]); |
Any updates on this? I have the same issue. Drawer that has snap points and dismissible set to false is still able to close. |
What's the problem with this one? Your code was incorrect, I edited a bunch of lines. |
@emilkowalski i have the same problem. Please provide example for drawer that cannot close but has snap points |
@IsaiahHarris Here you go mate - example |
@emilkowalski i'm still able to close the drawer with that demo. see video Untitled.mov |
@emilkowalski is there a communication issue I am missing? The issue is the drawer with snapPoints, and dismissible={false}, will still close. The expected behavior is that the drawer should not close. Currently there is no known way to have a drawer that stays on the page and is non dismissible that has snapPoints. Please let me know if you need any more information about the issue if I can clear up any confusion. cc: @imclint21 @xih |
No sorry I'm sure @emilkowalski will find time to manage this issue, then I could release our customers dashboard :D |
No communication issues, I just can’t reproduce it, it doesn’t close for me 🤔 This is interesting, I’ll look into it as soon as I have some spare time. It’ll be most likely this weekend as I’m pretty busy. Sorry about that! |
@emilkowalski awesome, I am open and willing to hopping on a video call to help you reproduce and contribute. It’s pretty simple to reproduce. Please feel free to reach out at [email protected] |
Which browser do you use btw? |
@imclint21 I am able to reproduce with 100% consistency on chrome and firefox |
me too, but I was asking to @emilkowalski :) |
|
Any updated on this? Please let me know if you need help reproducing @emilkowalski |
Same problem here |
Dirty workaround while this isn't fixed Use forceMount on the content and override the "use client";
import * as React from "react";
import { Drawer } from "vaul";
const snapPoints = ["148px", "355px", 1];
// Taken from https://github.com/emilkowalski/vaul/blob/main/src/constants.ts
const VELOCITY_THRESHOLD = 0.4;
export function MyDrawer() {
const [activeSnapPoint, setActiveSnapPoint] = React.useState<
number | string | null
>("148px");
const drawerSheetRef = React.useRef<HTMLDivElement>(null);
const previousDragYRef = React.useRef(0);
const dragStartTimeRef = React.useRef<Date>();
const minSnapPointHeight = drawerSheetRef.current
? getComputedStyle(drawerSheetRef.current).getPropertyValue(
"--snap-point-height",
)
: "0px";
function preventDrawerClose() {
setActiveSnapPoint(snapPoints[0]);
drawerSheetRef.current?.style.setProperty(
"transform",
`translate3d(0, ${minSnapPointHeight}, 0)`,
);
}
function checkDrawerBoundaries() {
if (
drawerSheetRef.current &&
drawerSheetRef.current.getBoundingClientRect().top >
parseInt(minSnapPointHeight)
) {
preventDrawerClose();
}
}
// Stops flicks from closing the drawer
function handleOnPointerUp(event: React.PointerEvent) {
const dragEndTime = new Date().getTime();
const dragStartTime = dragStartTimeRef.current
? dragStartTimeRef.current.getTime()
: 0;
const timeTaken = dragEndTime - dragStartTime;
const distanceMoved = previousDragYRef.current - event.screenY;
const dragVelocity = Math.abs(distanceMoved) / timeTaken;
const hasVelocityMetThreshold = dragVelocity > VELOCITY_THRESHOLD;
const hasDraggedUp = distanceMoved > 0;
if (hasVelocityMetThreshold && !hasDraggedUp) {
// setTimeout makes sure updates are ran after vaul's
setTimeout(() => {
preventDrawerClose();
}, 10);
}
}
return (
<Drawer.Root
open
dismissible={false}
modal={false}
snapPoints={snapPoints}
activeSnapPoint={activeSnapPoint}
setActiveSnapPoint={setActiveSnapPoint}
onDrag={checkDrawerBoundaries}
>
<Drawer.Portal forceMount>
<Drawer.Content
ref={drawerSheetRef}
asChild // asChild is needed in order to merge onPointer events without overriding vaul's
>
<div
data-state="open" // always open
vaul-drawer-visible="true"
className="flex flex-col max-w-md mx-auto w-full p-4 pt-5"
onPointerDown={(event) => {
previousDragYRef.current = event.screenY;
dragStartTimeRef.current = new Date();
}}
onPointerUp={handleOnPointerUp}
>
{/* ... */}
</div>
</Drawer.Content>
</Drawer.Portal>
</Drawer.Root>
);
} |
ah nice! |
@emilkowalski first time working with this repo, how often do releases come out? |
@imclint21 do you have any experiences with releases? |
It's not released atm @IsaiahHarris. Would be nice @emilkowalski to have a github action for autorelease. |
@emilkowalski any idea when this will get released? |
@IsaiahHarris This is released now! |
Hi,
I open this issue for centralise this problem:
After updating to the last version (0.7.8), and using snappoints, the drawer still dismissible, when it shouldn't.
Here is the code I'm using:
Regards
The text was updated successfully, but these errors were encountered: