Skip to content

Dialog: Focustrap doesnt work with only one tabbable component. #1903

@AndreHogberg

Description

@AndreHogberg

Describe the bug

When using the dialog component and you only got the close button, you can lose the focus trapping which makes you lose the ability to close the dialog using escape. It works fine with 2 buttons and 0 buttons. I tried looking at the code, and I suspect it is the following line:

Reproduction

https://stackblitz.com/edit/nrnpy3gb?file=src%2Froutes%2F%2Bpage.svelte

Logs

System Info

System:
    OS: Linux 6.6 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
    CPU: (32) x64 AMD Ryzen 9 9950X3D 16-Core Processor
    Memory: 25.10 GB / 30.17 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 24.11.0 - /home/arkuna/.nvm/versions/node/v24.11.0/bin/node
    npm: 11.6.1 - /home/arkuna/.nvm/versions/node/v24.11.0/bin/npm
    pnpm: 10.20.0 - /home/arkuna/.local/share/pnpm/pnpm
    bun: 1.3.3 - /home/arkuna/.bun/bin/bun
  npmPackages:
    @sveltejs/kit: ^2.48.5 => 2.49.0 
    bits-ui: ^2.14.4 => 2.14.4 
    svelte: ^5.43.8 => 5.43.14

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions