Roving-focus re-focus dismisses a just-opened modal Dialog (focusin light-dismiss)

Open Beginner friendly
#303 2 comments 0 reactions 0 assignees View on GitHub

@5at15h is already working on this.

Since Oct 6, 2026.

  • #304 by @5at15h — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
accessibility

Research direction

Start by examining the async re-focus logic in collection.rs around line 319 and the capturing focusin light-dismiss handler in dialog.rs around line 231 to confirm the reported race condition. Implement one of the two suggested fixes: either guard the async set_focus call to only run if document.activeElement is still inside the collection root, or modify the dialog handler to skip light-dismiss for modal dialogs when focus moves outside. Run the relevant component tests to verify the dialog stays open when opened immediately after a roving-focus selection change, and that non-modal dialog light-dismiss behavior remains intact.

Written by the indexing model from the issue text.

Description

Versions: dioxus 0.7.10 (desktop renderer, WKWebView on macOS); dioxus-primitives at 9a758255ea26e2b20c8cecf4c1c946feb9e71da7 (2026-09-07).

What happens

If a modal Dialog is opened right after a roving-focus collection (Tabs, RadioGroup, …) changes its focused item, the dialog opens and then immediately closes.

Steps to reproduce

  1. Render a Tabs (or RadioGroup), and a modal DialogRoot opened by a global keyboard shortcut (we use ⌘K for a command palette).
  2. Focus the tab list and press End. The selection moves to the last tab.
  3. Press the shortcut immediately, within a frame or two.

Expected: the dialog opens and stays open, with focus inside it.
Actual: the dialog opens and is dismissed at once. Focus ends up back on the tab. Pressing the shortcut again, after a moment, works.

The same happens after a pointer click that focuses the tab, on engines where a click focuses buttons (Chromium-based webviews, for example). WKWebView doesn't focus a button on click, so there only the keyboard path is exposed.

Why (from the source at 9a75825)

  • After a focus or selection change, the collection item re-focuses itself asynchronously. collection.rs control_mount_focus (around line 319) calls spawn(async move { md.set_focus(true).await }) whenever is_focused(index) is true. That set_focus lands one eval round trip later.
  • DialogContent registers use_outside_dismiss (dialog.rs around line 231; lib.rs around lines 212-229). It light-dismisses on a capturing focusin whose target is outside the dialog root, and it does this for modal dialogs too.
  • So the dialog opens and the focus trap moves focus inside. Then the collection's pending set_focus fires and focuses the tab outside the dialog. That focusin is treated as an outside interaction, and the dialog closes.

Suggested fixes (either would solve it)

  1. In the collection: only re-focus the item if focus is still within the collection, meaning document.activeElement is inside the collection root when the async set_focus runs. A late re-focus shouldn't steal focus that has moved elsewhere in the meantime.
  2. In the dialog: don't light-dismiss a modal dialog on focusin outside. A modal dialog already traps focus, and the WAI-ARIA dialog pattern doesn't close a modal dialog when focus moves programmatically. Keep pointerdown-outside dismissal for non-modal dialogs and popovers.

Happy to test a patch against our app.

Dominant language
Rust
Stars
358
Forks
90
Avg merge
54m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DioxusLabs/dioxus-components

All issues in DioxusLabs/dioxus-components

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.