Skip to content

[Bug]: Drawer state broken when nesting from another Drawer or DropdownMenu from Kobalte #80

@Vexcited

Description

@Vexcited

Bug description

In my app, I have a DropdownMenu from Kobalte and when clicking an item from this menu, it opens a Drawer from corvu using open and onOpenChange.

When I do this, it'll automatically close the Drawer. If I log the output of onOpenChange, it shows me false two times.

It does NOT only happens with elements from Kobalte, if I want to open another Drawer from a Drawer, it also does it.

Reproduction Link

https://stackblitz.com/edit/vexcited-corvu-drawer-issue-repro?file=src%2FApp.jsx

Reproduction Steps

  1. Click on Open Drawer
  2. Click on "Open another drawer !"
  3. See the new drawer close itself because of onOpenChange

Expected behavior

I expected the new drawer from not closing itself automatically.

Additional context

It's actually worse with an DropdownMenu item, because it'll close itself but after this I won't be able to interact anymore with the app because the drawer seems like to be still there.

2025-03-07.14-47-05.mp4

The code for this looks like this...

const [isReportDrawerOpened, setReportDrawerOpen] = createSignal(false);

return (
<>
 <Drawer open={isReportDrawerOpened()} onOpenChange={setReportDrawerOpen} breakPoints={[0.75]}>
  {(props) => (
    <>
      <Drawer.Trigger class="w-fit mx-auto rd-lg bg-white/10 px-4 py-3 text-lg font-medium transition-all duration-100 hover:bg-white/20 active:translate-y-0.5">
        Open Drawer
      </Drawer.Trigger>
      <Drawer.Portal>
        <Drawer.Overlay
          class="fixed inset-0 z-50 corvu-transitioning:transition-colors corvu-transitioning:duration-500 corvu-transitioning:ease-[cubic-bezier(0.32,0.72,0,1)]"
          style={{
            'background-color': `rgb(0 0 0 / ${
              0.5 * props.openPercentage
            })`,
          }}
        />
        <Drawer.Content class="corvu-transitioning:transition-transform corvu-transitioning:duration-500 corvu-transitioning:ease-[cubic-bezier(0.32,0.72,0,1)] fixed inset-x-0 bottom-0 z-50 flex h-full max-h-125 flex-col rounded-t-lg border-t-4 border-white/40 bg-black pt-3 after:absolute after:inset-x-0 after:top-[calc(100%-1px)] after:h-1/2 after:bg-inherit  md:select-none">
          <div class="h-1 w-10 self-center rounded-full bg-white/40" />
          <Drawer.Label class="mt-2 text-center text-xl font-bold">
            I'm a drawer!
          </Drawer.Label>
          <Drawer.Description class="mt-1 text-center">
            Drag down to close me.
          </Drawer.Description>
        </Drawer.Content>
      </Drawer.Portal>
    </>
  )}
 </Drawer>
 <DropdownMenu>
  <DropdownMenu.Trigger class="ml-auto hover:bg-white/8 rounded-full p-1.5 -mr-1.5 transition-colors">
    <DropdownMenu.Icon>
      <MdiDotsVertical class="text-xl" />
    </DropdownMenu.Icon>
  </DropdownMenu.Trigger>
  <DropdownMenu.Portal>
    <DropdownMenu.Content class="min-w-[220px] p-2 bg-[#080808] rounded-xl outline-none border border-white/8 transform-origin-[var(--kb-menu-content-transform-origin)]">
      <DropdownMenu.Item class="cursor-pointer rounded-lg py-1.5 px-4 hover:bg-white/8 text-red/80 hover:text-white"
        onSelect={() => setReportDrawerOpen(true)}
      >
        Report
      </DropdownMenu.Item>
    </DropdownMenu.Content>
  </DropdownMenu.Portal>
</DropdownMenu>
</>
);

2025-03-07.14-51-02.mp4

Also, thanks you so much for your quick patches, you're doing an awesome work and Corvu is such a treasure !

Metadata

Metadata

Assignees

Labels

bugUnexpected behaviour in the code of corvuhelp wantedExtra attention is needed

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions