Skip to content

Dialog does not return focus to triggering element #1707

@myieye

Description

@myieye

Describe the bug

The docs say:

When a Dialog closes, focus returns to the element that triggered its opening (typically the Dialog.Trigger).

I only see that happening if I either:

  1. Use <Dialog.Trigger> to open the dialog
  2. Close a nested dialog

I understand the docs to mean that it should also happen even if I use a simple <button> to set open to true.
But if I do that, then focus is returned to the body when the dialog is closed.

Reproduction

myieye@99acc00

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 AMD Ryzen 7 5825U with Radeon Graphics
    Memory: 4.94 GB / 22.83 GB
  Binaries:
    Node: 20.18.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 10.12.1 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (139.0.3405.86)
    Internet Explorer: 11.0.26100.1882
  npmPackages:
    svelte: catalog: => 5.33.2

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributions welcomeOpen to contributionsunder reviewBeing reviewed to determine whether it is an issue with Bits UI, a dependency, or user error.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions