vaul icon indicating copy to clipboard operation
vaul copied to clipboard

fix: `onOpenChange` getting called twice when user clicks outside of the drawer

Open phxgg opened this issue 11 months ago • 4 comments

Fixes: https://github.com/emilkowalski/vaul/issues/290

I tried to test as many possibilities as I could, and I couldn't find anything that breaks by deleting that line of code.

phxgg avatar Mar 07 '24 21:03 phxgg

@phxgg is attempting to deploy a commit to the emil Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Mar 07 '24 21:03 vercel[bot]

You said on this comment https://github.com/emilkowalski/vaul/issues/290#issuecomment-2002150057 that it was fixed in #297

However, #298 reintroduces the issue. I guess this is by accident?

phxgg avatar Mar 17 '24 00:03 phxgg

I have the same issue, so I had to create a quick hack around it. Hopefully this will get resolved soon

...
const [isFirstTimeOpened, setIsFirstTimeOpened] = useState(true);
...
const handleOnOpenChanges = useCallback(
    (aVal: boolean) => {
      if (isFirstTimeOpened) {
        setIsFirstTimeOpened(false);
        return;
      }
     ....
     }, [...]
);
... 

return (
    <Drawer
      open={open}
      onOpenChange={handleOnOpenChanges}
      direction={isDesktop ? "right" : "bottom"}
    >
    ... 
     </Drawer>
  );
};
    

Semkoo avatar May 06 '24 22:05 Semkoo

Good call! That callback doesn't belong there, since closeDrawer(), which is below it, calls it as well

artemis-prime avatar May 21 '24 15:05 artemis-prime

Fixed in #408

emilkowalski avatar Sep 13 '24 18:09 emilkowalski