Skip to content

onOpenChange and onOpenChangeComplete only firing on Dialog close (not open) #2006

@BenSaxon

Description

@BenSaxon

Describe the bug

Current Behaviour

The Dialog root component has props: onOpenChange and onOpenChangeComplete. These only fire when the sheet closes and not when it opens.

Try the code below to try for yourself.

<script lang="ts">
  import { Dialog } from "bits-ui";

  let isOpen = $state(false);
</script>

<button onclick={() => (isOpen = true)}>Open dialog</button>

<Dialog.Root
  bind:open={isOpen}
  onOpenChangeComplete={(open) => {
    console.log("onOpenChangeComplete", open);
  }}
  onOpenChange={(open) => {
    console.log("onOpenChange", open);
  }}
>
  <Dialog.Portal>
    <Dialog.Overlay class="fixed inset-0 z-50 bg-black/20" />
    <Dialog.Content
      class="fixed right-3 top-3 z-50 h-[calc(100%-24px)] w-full max-w-[420px] rounded-2xl bg-background p-6 shadow-lg"
    >
      <Dialog.Title class="text-base font-semibold">Basic Dialog</Dialog.Title>
      <p class="mt-2 text-sm">Simple open/close behavior.</p>
      <button
        class="mt-4 rounded border px-3 py-2"
        onclick={() => (isOpen = false)}
      >
        Close dialog
      </button>
    </Dialog.Content>
  </Dialog.Portal>
</Dialog.Root>

Expect Behaviour

I expect the logs to log when the dialog is opened, not just when it closes.

Reproduction

There is no stack blitz link in the dialog docs AFAICT https://bits-ui.com/docs/components/dialog

Logs

System Info

"svelte": "^5.55.0"
"bits-ui": "^2.16.3"
"@sveltejs/kit": "^2.50.0"

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageA maintainer needs to review this issue and label it appropriately

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions